Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #14698 nkRecWhen caused internalAssert in semConstructFields when generic type not mentioned in fields #14709

Merged
merged 3 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,10 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
result = t

# Slow path, we have some work to do
if result.n != nil and t.kind == tyObject:
if t.kind == tyRef and t.len > 0 and t[0].kind == tyObject and t[0].n != nil:
result.n = replaceObjBranches(cl, t[0].n)

elif result.n != nil and t.kind == tyObject:
# Invalidate the type size as we may alter its structure
result.size = -1
result.n = replaceObjBranches(cl, result.n)
Expand Down
20 changes: 20 additions & 0 deletions tests/objects/tobject.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,23 @@ var b: TMyObj = a
type
InheritableFoo {.inheritable.} = ref object
InheritableBar = ref object of InheritableFoo # ERROR.

block: # bug #14698
const N = 3
type Foo[T] = ref object
x1: int
when N == 2:
x2: float
when N == 3:
x3: seq[int]
else:
x4: char
x4b: array[9, char]

let t = Foo[float](x1: 1)
doAssert $(t[]) == "(x1: 1, x3: @[])"
doAssert t.sizeof == int.sizeof
type Foo1 = object
x1: int
x3: seq[int]
doAssert t[].sizeof == Foo1.sizeof