Skip to content

Commit 46bfe90

Browse files
committed
Don't allow implicit conversions on prefixes of type selections
Fixes #19888
1 parent 3694d95 commit 46bfe90

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
714714
val elems = qual.tpe.widenTermRefExpr.tupleElementTypes.getOrElse(Nil)
715715
typedSelect(tree, pt, qual.cast(defn.tupleType(elems)))
716716
else
717-
val tree1 = tryExtensionOrConversion(
717+
val tree1 = {
718+
if selName.isTypeName then EmptyTree
719+
else tryExtensionOrConversion(
718720
tree, pt, IgnoredProto(pt), qual, ctx.typerState.ownedVars, this, inSelect = true)
719-
.orElse {
721+
}.orElse {
720722
if ctx.gadt.isNarrowing then
721723
// try GADT approximation if we're trying to select a member
722724
// Member lookup cannot take GADTs into account b/c of cache, so we

tests/neg/i11994.check

+10-24
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
-- [E008] Not Found Error: tests/neg/i11994.scala:2:28 -----------------------------------------------------------------
2-
2 |implicit def foo[T <: Tuple.meow]: Unit = ??? // error
3-
| ^^^^^^^^^^
4-
| type meow is not a member of object Tuple.
5-
| Extension methods were tried, but the search failed with:
6-
|
7-
| Cyclic reference involving method foo
8-
|
9-
| The error occurred while trying to compute the signature of method foo
10-
| which required to compute the signature of type T
11-
| which required to compute the signature of method foo
12-
|
13-
| Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace.
14-
-- [E008] Not Found Error: tests/neg/i11994.scala:3:18 -----------------------------------------------------------------
1+
-- [E046] Cyclic Error: tests/neg/i11994.scala:3:18 --------------------------------------------------------------------
152
3 |given [T <: Tuple.meow]: Unit = ??? // error
16-
| ^^^^^^^^^^
17-
| type meow is not a member of object Tuple.
18-
| Extension methods were tried, but the search failed with:
3+
| ^
4+
| Cyclic reference involving method given_Unit
5+
|
6+
| The error occurred while trying to compute the signature of given instance given_Unit
7+
| which required to compute the signature of type T
8+
| which required to compute the signature of given instance given_Unit
9+
|
10+
| Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace.
1911
|
20-
| Cyclic reference involving method given_Unit
21-
|
22-
| The error occurred while trying to compute the signature of given instance given_Unit
23-
| which required to compute the signature of type T
24-
| which required to compute the signature of given instance given_Unit
25-
|
26-
| Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace.
12+
| longer explanation available when compiling with `-explain`

tests/neg/i19888.scala

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object Main{
2+
object Foo
3+
object Bar{ type Qux = Unit }
4+
5+
6+
implicit def conv(f: Foo.type): Bar.type = Bar
7+
8+
def B: Bar.type = Bar
9+
10+
def main(args: Array[String]): Unit = {
11+
val x: Foo.Qux = null // error
12+
val y: B.Qux = null
13+
println(x)
14+
println(y)
15+
}
16+
}

0 commit comments

Comments
 (0)