Skip to content

Commit 3d5cf9c

Browse files
authored
Don't allow implicit conversions on prefixes of type selections (#19934)
Fixes #19888
2 parents a74470c + b5cff57 commit 3d5cf9c

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ trait ImportSuggestions:
158158
// Candidates that are already available without explicit import because they
159159
// are already provided by the context (imported or inherited) or because they
160160
// are in the implicit scope of `pt`.
161-
val alreadyAvailableCandidates: Set[Symbol] = {
161+
lazy val alreadyAvailableCandidates: Set[Symbol] = {
162162
val wildProto = wildApprox(pt)
163163
val contextualCandidates = ctx.implicits.eligible(wildProto)
164164
val implicitScopeCandidates = ctx.run.nn.implicitScope(wildProto).eligible

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
720720
val elems = qual.tpe.widenTermRefExpr.tupleElementTypes.getOrElse(Nil)
721721
typedSelect(tree, pt, qual.cast(defn.tupleType(elems)))
722722
else
723-
val tree1 = tryExtensionOrConversion(
723+
val tree1 = {
724+
if selName.isTypeName then EmptyTree
725+
else tryExtensionOrConversion(
724726
tree, pt, IgnoredProto(pt), qual, ctx.typerState.ownedVars, this, inSelect = true)
725-
.orElse {
727+
}.orElse {
726728
if ctx.gadt.isNarrowing then
727729
// try GADT approximation if we're trying to select a member
728730
// Member lookup cannot take GADTs into account b/c of cache, so we

tests/neg/i11994.check

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
11
-- [E008] Not Found Error: tests/neg/i11994.scala:2:28 -----------------------------------------------------------------
22
2 |implicit def foo[T <: Tuple.meow]: Unit = ??? // error
33
| ^^^^^^^^^^
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.
4+
| type meow is not a member of object Tuple
145
-- [E008] Not Found Error: tests/neg/i11994.scala:3:18 -----------------------------------------------------------------
156
3 |given [T <: Tuple.meow]: Unit = ??? // error
167
| ^^^^^^^^^^
17-
| type meow is not a member of object Tuple.
18-
| Extension methods were tried, but the search failed with:
19-
|
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.
8+
| type meow is not a member of object Tuple

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)