mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 18:02:05 +00:00
fixes #24112
Sym nodes in templates that could be open are [given `nil`
type](22d2cf2175/compiler/semtempl.nim (L274))
when `--experimentalOpenSym` is disabled so that they can be semchecked
to give a warning since #24007. The first nodes of object constructors
(in this case) and in type conversions don't replace their first node
(the symbol) with a typechecked one, they only call `semTypeNode` on it
and leave it as is.
Effect tracking checks if the type of a sym node has a destructor to
check if the node type should be replaced with the sym type. But this
causes a segfault when the type of the node is nil. To fix this, we
always set the node type to the sym type if the node type is nil.
Alternatively `semObjConstr` and `semConv` could be changed to set the
type of their first node to the found type but I'm not sure if this
would break anything. They could call `semExprWithType` on the first
node but `semTypeNode` would still have to be called (maybe call it
before?). This isn't a problem if the sym node has a type but is just
nested in `nkOpenSym` or `nkOpenSymChoice` which have nil type instead
(i.e. with openSym enabled), so maybe this still is the "most general"
solution, I don't know.
20 lines
593 B
Nim
20 lines
593 B
Nim
discard """
|
|
matrix: "--skipParentCfg --filenames:legacyRelProj --hints:off"
|
|
action: reject
|
|
"""
|
|
|
|
# issue #24112, needs --experimental:openSym disabled
|
|
|
|
block: # simplified
|
|
type
|
|
SomeObj = ref object # Doesn't error if you make SomeObj be non-ref
|
|
template foo = yield SomeObj()
|
|
when compiles(foo): discard
|
|
|
|
import std/asyncdispatch
|
|
block:
|
|
proc someProc(): Future[void] {.async.} = discard
|
|
proc foo() =
|
|
await someProc() #[tt.Error
|
|
^ Can only 'await' inside a proc marked as 'async'. Use 'waitFor' when calling an 'async' proc in a non-async scope instead]#
|