summary refs log tree commit diff stats
diff options
context:
space:
mode:
authormetagn <10591326+metagn@users.noreply.github.com>2022-01-19 14:38:14 +0300
committerGitHub <noreply@github.com>2022-01-19 12:38:14 +0100
commit08261cb9e33445553144219023900b4ced0b0f55 (patch)
tree6661f3e118bc0d3320e32757c117f0fef6edb13f
parent5d34e81f2363e1de97916ac60b028b9a8b287a4b (diff)
downloadNim-08261cb9e33445553144219023900b4ced0b0f55.tar.gz
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.
-rw-r--r--compiler/semtypes.nim6
-rw-r--r--tests/types/tnontype.nim9
2 files changed, 13 insertions, 2 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index d03fa88a8..b4f385fe6 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -1993,8 +1993,10 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
   of nkStmtListType: result = semStmtListType(c, n, prev)
   of nkBlockType: result = semBlockType(c, n, prev)
   else:
-    localError(c.config, n.info, "type expected, but got: " & renderTree(n))
-    result = newOrPrevType(tyError, prev, c)
+    result = semTypeExpr(c, n, prev)
+    when false:
+      localError(c.config, n.info, "type expected, but got: " & renderTree(n))
+      result = newOrPrevType(tyError, prev, c)
   n.typ = result
   dec c.inTypeContext
 
diff --git a/tests/types/tnontype.nim b/tests/types/tnontype.nim
new file mode 100644
index 000000000..4e2bafb32
--- /dev/null
+++ b/tests/types/tnontype.nim
@@ -0,0 +1,9 @@
+discard """
+  errormsg: "expected type, but got: 3"
+"""
+
+type
+  Foo = (block:
+    int)
+  
+  Bar = 3