-
Notifications
You must be signed in to change notification settings - Fork 1.1k
TypeTest of TypeBlock of Quotes API matches every Block #21721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Milestone
Comments
felher
added a commit
to felher/dotty
that referenced
this issue
Oct 7, 2024
TypeBlocks are represented as normal Blocks in the Quotes API. The current TypeTest for TypeBlock is exactly the same as the TypeTest for Block, which means that case TypeBlock(_, _) matches every block. The implementation of unapply on TypeBlockModule, however, gives back (List[TypeDef], TypeTree). It constructs the List[TypeDef] by mapping over every statement, turning it into a TypeDef by using a match with the pattern case alias: TypeDef => alias Since the TypeTest matches any Block and not only Blocks that are TypeBlocks, the statemnts can be anything, not just TypeDefs, which lets the whole case TypeBlock(_, _) pattern fail with a MatchError. This commit fixes the problem by making the TypeTest check whether the Block is a type (which in turns checks whether the blocks expression is a type)
jchyb
added a commit
that referenced
this issue
Mar 4, 2025
`TypeBlock`s are represented as normal `Blocks` in the Quotes API's implementation. The current `TypeTest` for `TypeBlock` is exactly the same as the `TypeTest` for `Block`, which means that `case TypeBlock(_, _)` "matches" every block. The implementation of `unapply` on `TypeBlockModule`, however, gives back `(List[TypeDef], TypeTree)`. It constructs the `List[TypeDef]` by mapping over every statement of the block, trying to turn it into a `TypeDef` by using a match with the pattern ```scala case alias: TypeDef => alias ``` This seems fine since `TypeBlock`s are supposed to be just a list of `TypeDefs` followed by a type as the last expression. Since the `TypeTest` matches any `Block` and not only `Blocks` that are `TypeBlocks`, the statements can be anything, not just `TypeDef`s, which lets the whole `case TypeBlock(_, _)` pattern die with a `MatchError`. This commit fixes the problem by making the `TypeTest` check whether the `Block` is a type (which in turns checks whether the `Block`s expression is a type) Closes #21721
tgodzik
pushed a commit
to scala/scala3-lts
that referenced
this issue
Apr 23, 2025
TypeBlocks are represented as normal Blocks in the Quotes API. The current TypeTest for TypeBlock is exactly the same as the TypeTest for Block, which means that case TypeBlock(_, _) matches every block. The implementation of unapply on TypeBlockModule, however, gives back (List[TypeDef], TypeTree). It constructs the List[TypeDef] by mapping over every statement, turning it into a TypeDef by using a match with the pattern case alias: TypeDef => alias Since the TypeTest matches any Block and not only Blocks that are TypeBlocks, the statemnts can be anything, not just TypeDefs, which lets the whole case TypeBlock(_, _) pattern fail with a MatchError. This commit fixes the problem by making the TypeTest check whether the Block is a type (which in turns checks whether the blocks expression is a type) [Cherry-picked 147f562]
tgodzik
added a commit
to scala/scala3-lts
that referenced
this issue
Apr 24, 2025
Backport "Fix scala#21721: make case TypeBlock(_, _) not match non-type Block" to 3.3 LTS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Compiler version
3.5.1 (and way before, as far as I can see)
Minimized code
Test.scala
Macro.scala
Output
Expectation
There should be no match error here. It should just compile fine.
PR
PR attempt for a fix here: #21722
The text was updated successfully, but these errors were encountered: