-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expanding a pattern match leads to "head of empty list" #1846
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
Comments
This is related to #1774 , blocks inside patterns is not well supported in Dotty. In Scalac, the code above is syntactically invalid, but the pattern matcher can handle blocks that are synthesized. |
I guess the problem for this particular issue is that the grammar allows path selections and blocks at the same time. Is there any reason why you would want to select a member of a block? At least the examples in #1774 don't do that. I could imagine an example like: x match {
case {
object Even {
def unapply(n: Int): Boolean = n % 2 == 0
}
object foo {
val even = Even
}
foo
}.even => 42
} But here Dotty tells me: -- [E008] Member Not Found Error: examples/bug.scala ---------------------------
9 | case {
10 | object Even {
11 | def unapply(n: Int): Boolean = n % 2 == 0
12 | }
13 | object foo {
14 | val even = Even
15 | }
16 | foo
| ^
| value `even` is not a member of Object - did you mean `Object.eq`? If we want to forbid selection of blocks, I guess we need to change the grammar to SimplePattern1 ::= Path
| `{' Block `}'
- | SimplePattern1 `.' id Other selections like |
The current exception is exception while typing 42.toString.unapply of class class dotty.tools.dotc.ast.Trees$Select # 89
exception while typing 42.toString() of class class dotty.tools.dotc.ast.Trees$Apply # 78
exception while typing Bug.x match
{
case 42.toString() => 42
} of class class dotty.tools.dotc.ast.Trees$Match # 81
exception while typing
final module
class Bug() extends Object() {
val x: Int = 42
Bug.x match
{
case 42.toString() => 42
}
} of class class dotty.tools.dotc.ast.Trees$TypeDef # 84
exception while typing package <empty> {
final lazy module val Bug: Bug = new Bug()
final module
class Bug() extends Object() {
val x: Int = 42
Bug.x match
{
case 42.toString() => 42
}
}
} of class class dotty.tools.dotc.ast.Trees$PackageDef # 85 |
When trying to compile this syntactically correct, but nonsensical program the compiler crashes:
Beginning of the trace:
The text was updated successfully, but these errors were encountered: