diff options
| author | metagn <metagngn@gmail.com> | 2024-09-11 12:55:09 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-11 11:55:09 +0200 |
| commit | 9dda7ff7bccec58937be450564f55d308fb2b07e (patch) | |
| tree | 8cc1b5d80aabe046c22929f2bc38a438adde2391 /tests | |
| parent | 771369237c579afb93935c8bef5e3c79155ddfd6 (diff) | |
| download | Nim-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')
| -rw-r--r-- | tests/generics/tuninstantiatedgenericcalls.nim | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/generics/tuninstantiatedgenericcalls.nim b/tests/generics/tuninstantiatedgenericcalls.nim index a1f5a0cb6..308b1f33e 100644 --- a/tests/generics/tuninstantiatedgenericcalls.nim +++ b/tests/generics/tuninstantiatedgenericcalls.nim @@ -435,3 +435,9 @@ block: # issue #24090 proc foo[T: M](x: T = default(T)) = discard x foo[M[int]]() doAssert not compiles(foo()) + +block: # above but encountered by sigmatch using replaceTypeVarsN + type Opt[T] = object + proc none[T](x: type Opt, y: typedesc[T]): Opt[T] = discard + proc foo[T](x: T, a = Opt.none(int)) = discard + foo(1, a = Opt.none(int)) |