diff options
-rw-r--r-- | compiler/semexprs.nim | 2 | ||||
-rw-r--r-- | compiler/semmagic.nim | 7 | ||||
-rw-r--r-- | tests/errmsgs/t10594.nim | 7 |
3 files changed, 14 insertions, 2 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 1b8a978ec..239dbad54 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -15,7 +15,7 @@ const errXExpectsTypeOrValue = "'$1' expects a type or value" errVarForOutParamNeededX = "for a 'var' type a variable needs to be passed; but '$1' is immutable" errXStackEscape = "address of '$1' may not escape its stack frame" - errExprHasNoAddress = "expression has no address; maybe use 'unsafeAddr'" + errExprHasNoAddress = "expression has no address" errCannotInterpretNodeX = "cannot evaluate '$1'" errNamedExprExpected = "named expression expected" errNamedExprNotAllowed = "named expression not allowed here" diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index 2311136b4..6e5563d69 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -16,7 +16,12 @@ proc semAddr(c: PContext; n: PNode; isUnsafeAddr=false): PNode = if x.kind == nkSym: x.sym.flags.incl(sfAddrTaken) if isAssignable(c, x, isUnsafeAddr) notin {arLValue, arLocalLValue}: - localError(c.config, n.info, errExprHasNoAddress) + # Do not suggest the use of unsafeAddr if this expression already is a + # unsafeAddr + if isUnsafeAddr: + localError(c.config, n.info, errExprHasNoAddress) + else: + localError(c.config, n.info, errExprHasNoAddress & "; maybe use 'unsafeAddr'") result.add x result.typ = makePtrType(c, x.typ) diff --git a/tests/errmsgs/t10594.nim b/tests/errmsgs/t10594.nim new file mode 100644 index 000000000..c9506c542 --- /dev/null +++ b/tests/errmsgs/t10594.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "expression has no address" + line: 7 +""" + +template foo(v: varargs[int]) = unsafeAddr v +foo(1, 2) |