Do not raise from Crystal::Type#lookup_type?
if union type cannot be stored
#16123
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.
Resolves #12616.
The following snippet, which does not compile, complains about an invalid union type:
But this union is permitted here, because def parameter restrictions do not name an actual type of a variable:
The compiler already knows that there is a "no overload matches" error here. However, while producing the error message, the compiler attempts to resolve the
Array
type in order to show which argument types are not covered by the parameter restriction. This lookup is allowed to fail, but it should never raise, otherwise theuse a more specific type
error prevails, as shown above. It is up to other places in the compiler to reject union types that cannot be stored, e.g. instance variable declarations.Some other uses of
Crystal::Type#lookup_type?
are more subtle. For example, overload ordering betweenGeneric
andPath
nodes calls this method:The first overload is now ordered before the second overload. (This is a simplified rule that happens to work for common uses of generics with free variables, and is not 100% correct.)