Skip to content

Commit

Permalink
fix is with type/typedesc crashing the compiler (#23967)
Browse files Browse the repository at this point in the history
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?

(cherry picked from commit 995081b)
  • Loading branch information
metagn authored and narimiran committed Sep 13, 2024
1 parent 5f09bf1 commit f86f292
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,7 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode =
n[1] = makeTypeSymNode(c, lhsType, n[1].info)
lhsType = n[1].typ
else:
if lhsType.base.kind == tyNone or
(c.inGenericContext > 0 and lhsType.base.containsGenericType):
if c.inGenericContext > 0 and lhsType.base.containsGenericType:
# BUGFIX: don't evaluate this too early: ``T is void``
return

Expand Down
4 changes: 4 additions & 0 deletions tests/types/tisopr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,7 @@ block: # previously tisop.nim
doAssert f.y.typeof is float
doAssert f.z.typeof is float
p(A, f)

block: # issue #22850
doAssert not (type is int)
doAssert not (typedesc is int)

0 comments on commit f86f292

Please sign in to comment.