make sigmatch use prepareNode for tyFromExpr #24095
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes regression remaining after #24092
In #24092
prepareNode
was updated so it wouldn't try to instantiate generic type symbols (likeGeneric
whentype Generic[T] = object
, andprepareNode
is whattyFromExpr
uses in most of the compiler. An exception is in sigmatch, which is now changed to useprepareNode
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 generatetyFromExpr
in generic contexts since #24005, including generic type symbols. But this means when we try to instantiate thetyFromExpr
in sigmatch, which increasesc.inGenericContext
for potentially remaining unresolved expressions, dotcalls stay astyFromExpr
and so never match. To fix this, we change the "generic type" check in dot fields andtypedesc
matching to an "unresolved type" check which excludes generic body types; and for generic body types, we only generatetyFromExpr
if the dot field is a generic parameter of the generic type (so that it gets resolved only at instantiation).Notes for the future:
inc c.inGenericContext
, if atyFromExpr
can't instantiate it's fine if we just fail the match (i.e. redirect the instantiation errors fromsemtypinst
to a match failure). Then again maybe this is the best way to check for inability to instantiate.elif c.inGenericContext > 0 and t.containsUnresolvedType
check in dotfields could maybe be simplified to just checking fortyFromExpr
andtyGenericParam
, but I don't know if this is an exhaustive list.