summary refs log tree commit diff stats
path: root/tests/stdlib/twith.nim
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2024-09-11 12:55:09 +0300
committerGitHub <noreply@github.com>2024-09-11 11:55:09 +0200
commit9dda7ff7bccec58937be450564f55d308fb2b07e (patch)
tree8cc1b5d80aabe046c22929f2bc38a438adde2391 /tests/stdlib/twith.nim
parent771369237c579afb93935c8bef5e3c79155ddfd6 (diff)
downloadNim-9dda7ff7bccec58937be450564f55d308fb2b07e.tar.gz
make sigmatch use prepareNode for tyFromExpr (#24095)
fixes regression remaining after #24092

In #24092 `prepareNode` was updated so it wouldn't try to instantiate
generic type symbols (like `Generic` when `type Generic[T] = object`,
and `prepareNode` is what `tyFromExpr` uses in most of the compiler. An
exception is in sigmatch, which is now changed to use `prepareNode` to
make generic type symbols work in the same way as usual. However this
requires another change to work:

Dot fields and matches to `typedesc` on generic types generate
`tyFromExpr` in generic contexts since #24005, including generic type
symbols. But this means when we try to instantiate the `tyFromExpr` in
sigmatch, which increases `c.inGenericContext` for potentially remaining
unresolved expressions, dotcalls stay as `tyFromExpr` and so never
match. To fix this, we change the "generic type" check in dot fields and
`typedesc` matching to an "unresolved type" check which excludes generic
body types; and for generic body types, we only generate `tyFromExpr` if
the dot field is a generic parameter of the generic type (so that it
gets resolved only at instantiation).

Notes for the future:

* Sigmatch shouldn't have to `inc c.inGenericContext`, if a `tyFromExpr`
can't instantiate it's fine if we just fail the match (i.e. redirect the
instantiation errors from `semtypinst` to a match failure). Then again
maybe this is the best way to check for inability to instantiate.
* The `elif c.inGenericContext > 0 and t.containsUnresolvedType` check
in dotfields could maybe be simplified to just checking for `tyFromExpr`
and `tyGenericParam`, but I don't know if this is an exhaustive list.
Diffstat (limited to 'tests/stdlib/twith.nim')
0 files changed, 0 insertions, 0 deletions