Skip to content

Commit

Permalink
fixes #11747
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Jul 17, 2019
1 parent 102b71f commit 15d2a92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,9 @@ proc semDeref(c: PContext, n: PNode): PNode =
var t = skipTypes(n.sons[0].typ, {tyGenericInst, tyVar, tyLent, tyAlias, tySink, tyOwned})
case t.kind
of tyRef, tyPtr: n.typ = t.lastSon
of tyTypeDesc:
# typeof(x[]) is still a typedesc:
n.typ = makeTypeDesc(c, t.lastSon.lastSon)
else: result = nil
#GlobalError(n.sons[0].info, errCircumNeedsPointer)

Expand Down
14 changes: 14 additions & 0 deletions tests/metatype/ttypedesc3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ proc Child
method Base
yield Base
yield Child
12
'''
"""

Expand All @@ -27,3 +28,16 @@ when false:

for s in Base.it: echo s
for s in Child.it: echo s #<- bug #2662


# bug #11747

type
MyType = object
a: int32
b: int32
c: int32

MyRefType = ref MyType

echo sizeof(MyRefType[])

1 comment on commit 15d2a92

@zah
Copy link
Member

@zah zah commented on 15d2a92 Jul 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix looks slightly fishy. What prevents me from dereferencing types that are not refs and pointers? The results will be quite surprising for some types.

Also, it won't work properly for user-defined smart pointer types. A solution based on overloads in system.nim would have been more appropriate IMO.

Please sign in to comment.