Fix #21721: make case TypeBlock(_, _) not match non-type Block #21722
+18
−1
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.
TypeBlock
s are represented as normalBlocks
in the Quotes API's implementation. The currentTypeTest
forTypeBlock
is exactly the same as theTypeTest
forBlock
, which means thatcase TypeBlock(_, _)
"matches" every block.The implementation of
unapply
onTypeBlockModule
, however, gives back(List[TypeDef], TypeTree)
. It constructs theList[TypeDef]
by mapping over every statement of the block, trying to turn it into aTypeDef
by using a match with the patternThis seems fine since
TypeBlock
s are supposed to be just a list ofTypeDefs
followed by a type as the last expression. Since theTypeTest
matches anyBlock
and not onlyBlocks
that areTypeBlocks
, the statements can be anything, not justTypeDef
s, which lets the wholecase TypeBlock(_, _)
pattern die with aMatchError
.This commit fixes the problem by making the
TypeTest
check whether theBlock
is a type (which in turns checks whether theBlock
s expression is a type)This is my first PR, please let me know if I should change anything or am completely going about fixing this the wrong way, etc.
Also, I could not run the complete test suite on my machine, it died even without making any changes. But I could at least run the positive compilation tests.
Closes #21721