Skip to content

Commit eec1562

Browse files
committed
Issue an error when trying to use a method as a qualifier.
The check for `implicitsEnabled` here seems older even than that method; it appears to originally have looked at a flag `reportGeneralErrors`, which seems a reasonable flag if you want to check whether to report an error. An erroneous tree that we do not error on, however, can be use as a qualifier which will not necessarily cause an error until past typer, when something finally notices the mistake and blows up. Fixes scala/bug#10474.
1 parent 1b7d57f commit eec1562

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,10 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
894894

895895
def cantAdapt =
896896
if (context.implicitsEnabled) MissingArgsForMethodTpeError(tree, meth)
897-
else setError(tree)
897+
else if (mode.inQualMode) UnstableTreeError(tree)
898+
else setError(tree) // scala/bug#10474 implies that not issuing an
899+
// error here might be harmful... can we get here
900+
// with implicits disabled and not in QUALmode?
898901

899902
// constructors do not eta-expand
900903
if (meth.isConstructor) cantAdapt

test/files/neg/t10474.check

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
t10474.scala:9: error: stable identifier required, but Test.this.Foo found.
2+
case Foo.Bar ⇒ true
3+
^
4+
t10474.scala:13: error: stable identifier required, but Test.this.Foo found.
5+
type Crash = Foo.type
6+
^
7+
t10474.scala:17: error: stable identifier required, but Test.this.bingo found.
8+
val `bingo`.Fuzz = 1
9+
^
10+
three errors found

test/files/neg/t10474.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package t10474
2+
3+
object Test {
4+
def Foo(a: Int): Char = ???
5+
6+
object Bar
7+
8+
def crash[A](): Boolean = Bar match {
9+
case Foo.Bar true
10+
case _ false
11+
}
12+
13+
type Crash = Foo.type
14+
15+
def bingo(l: Int, r: Int) = l + r
16+
17+
val `bingo`.Fuzz = 1
18+
}

0 commit comments

Comments
 (0)