Skip to content

Commit fe5edb7

Browse files
metagnnarimiran
authored andcommitted
Don't reject types directly on AST (#19407)
Instead of rejecting type expressions based on node kind, evaluate the expression as a type. This is already the behavior for call results, and it has its own error for non-types, which is the same error you would normally get with 2 words swapped. (cherry picked from commit 08261cb)
1 parent de6d7dc commit fe5edb7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

compiler/semtypes.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,8 +1993,10 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
19931993
of nkStmtListType: result = semStmtListType(c, n, prev)
19941994
of nkBlockType: result = semBlockType(c, n, prev)
19951995
else:
1996-
localError(c.config, n.info, "type expected, but got: " & renderTree(n))
1997-
result = newOrPrevType(tyError, prev, c)
1996+
result = semTypeExpr(c, n, prev)
1997+
when false:
1998+
localError(c.config, n.info, "type expected, but got: " & renderTree(n))
1999+
result = newOrPrevType(tyError, prev, c)
19982000
n.typ = result
19992001
dec c.inTypeContext
20002002

tests/types/tnontype.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
discard """
2+
errormsg: "expected type, but got: 3"
3+
"""
4+
5+
type
6+
Foo = (block:
7+
int)
8+
9+
Bar = 3

0 commit comments

Comments
 (0)