Skip to content

Error msg/stable identifiers #5334

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public enum ErrorMessageID {
LazyStaticFieldID,
StaticOverridingNonStaticMembersID,
OverloadInRefinementID,
NoMatchingOverloadID
NoMatchingOverloadID,
StableIdentPatternID
;

public int errorNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2191,4 +2191,11 @@ object messages {
val kind: String = "Type Mismatch"
val explanation: String = ""
}
case class StableIdentPattern(tree: untpd.Tree, pt: Type)(implicit val ctx: Context)
extends Message(StableIdentPatternID) {
override def kind: String = "Syntax"
override def msg: String =
hl"""Stable identifier required, but ${tree.show} found"""
override def explanation: String = ""
}
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class Typer extends Namer
!pt.isInstanceOf[ApplyingProto] &&
!tree.tpe.isStable &&
!isWildcardArg(tree))
ctx.error(s"stable identifier required, but ${tree.show} found", tree.pos)
ctx.error(StableIdentPattern(tree, pt), tree.pos)

tree
}
Expand Down
20 changes: 20 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1605,4 +1605,24 @@ class ErrorMessagesTests extends ErrorMessagesTest {
message.msg
)
}

@Test def StableIdentifiers() =
checkMessagesAfter(FrontEnd.name) {
"""
| object Test {
| var x = 2
| def test = 2 match {
| case `x` => x + 1
| }
| }
""".stripMargin
}.expect { (_, messages) =>
assertMessageCount(1, messages)
val message = messages.head
assertTrue(message.isInstanceOf[StableIdentPattern])
assertEquals(
"Stable identifier required, but `x` found",
message.msg
)
}
}