diff options
author | Jake Leahy <jake@leahy.dev> | 2023-12-17 22:29:46 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-17 12:29:46 +0100 |
commit | b3b87f0f8a8091c88461953d686f9772dfb3c4bc (patch) | |
tree | 8ef9fcd765ce6c0927ba4d3e394b688946193488 /compiler | |
parent | 0bd4d802383518cfbb43fa02375602abdfb6114f (diff) | |
download | Nim-b3b87f0f8a8091c88461953d686f9772dfb3c4bc.tar.gz |
Mark `macros.error` as `.noreturn.` (#23081)
Closes #14329 Marks `macros.error` as `.noreturn` so that it can be used in expressions. This also fixes the issue that occurred in #19659 where a stmt that could be an expression (Due to having `discardable` procs at the end of other branches) would believe a `noreturn` proc is returning the same type e.g. ```nim proc bar(): int {.discardable.} = discard if true: bar() else: quit(0) # Says that quit is of type `int` and needs to be used/discarded except it actually has no return type ```
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/condsyms.nim | 1 | ||||
-rw-r--r-- | compiler/semstmts.nim | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 5865e5310..085576c6b 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -157,6 +157,7 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimAllowNonVarDestructor") defineSymbol("nimHasQuirky") defineSymbol("nimHasEnsureMove") + defineSymbol("nimHasNoReturnError") defineSymbol("nimUseStrictDefs") defineSymbol("nimHasNolineTooLong") diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index eacda7f9b..a0eda36d1 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -169,6 +169,11 @@ proc discardCheck(c: PContext, result: PNode, flags: TExprFlags) = while n.kind in skipForDiscardable: if n.kind == nkTryStmt: n = n[0] else: n = n.lastSon + + # Ignore noreturn procs since they don't have a type + if n.endsInNoReturn: + return + var s = "expression '" & $n & "' is of type '" & result.typ.typeToString & "' and has to be used (or discarded)" if result.info.line != n.info.line or |