Fix #10178: Put the wildcard demon back in the bottle #10195
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.
This was a very interesting bug. Why did
any2stringadd
appear out of the blue?The first observation was that it was resolved by an import of an identifier with
_
as its name. Why? Because we have a standard predefined importThis is represented as a "rename" from
anyToStringAdd
to_
, assuming thatno real identifier could be
_
. But that assumption turned out to be wrong.How did we end up with an identifier
_
that needed to be resolved? This was asecond bug in Desugar, method
makeIdPat
. Here we needed to create binds for partsof a pattern. If the pattern was already a Bind, we used that one instead. But the
Bind
in question was anonymous, using_
as the pattern variable. So we did notreplace that by a fresh identifier, but used
_
as the identifier instead. However,_
is treated specially as a binder; it does not generate a symbol in the enclosingscope. So resolving the
_
identifier did not see the enclosing bind and searchedfurther out instead, until it found the "renamed" import. Beautiful! It shows that
treating wildcards as some sort of identifiers is fraught with surprises.