Skip to content

Commit 995081b

Browse files
authored
fix is with type/typedesc crashing the compiler (#23967)
fixes #22850 The `is` operator checks the type of the left hand side, and if it's generic or if it's a `typedesc` type with no base type, it leaves it to be evaluated later. But `typedesc` types with no base type precisely describe the default typeclass `type`/`typeclass`, so this condition is removed. Maybe at some point this represented an unresolved generic type?
1 parent d43a595 commit 995081b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

compiler/semexprs.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
611611
n[1] = makeTypeSymNode(c, lhsType, n[1].info)
612612
lhsType = n[1].typ
613613
else:
614-
if lhsType.base.kind == tyNone or
615-
(c.inGenericContext > 0 and lhsType.base.containsGenericType):
614+
if c.inGenericContext > 0 and lhsType.base.containsGenericType:
616615
# BUGFIX: don't evaluate this too early: ``T is void``
617616
return
618617

tests/types/tisopr.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,7 @@ block: # previously tisop.nim
165165
doAssert f.y.typeof is float
166166
doAssert f.z.typeof is float
167167
p(A, f)
168+
169+
block: # issue #22850
170+
doAssert not (type is int)
171+
doAssert not (typedesc is int)

0 commit comments

Comments
 (0)