Skip to content

Commit d311bf6

Browse files
authored
Merge pull request #10316 from dotty-staging/fix-#10311
2 parents 93f24a0 + e4494c3 commit d311bf6

File tree

6 files changed

+52
-14
lines changed

6 files changed

+52
-14
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ object desugar {
2323
import untpd._
2424
import DesugarEnums._
2525

26-
/** If a Select node carries this attachment, suppress the check
27-
* that its type refers to an acessible symbol.
28-
*/
29-
val SuppressAccessCheck: Property.Key[Unit] = Property.Key()
30-
3126
/** An attachment for companion modules of classes that have a `derives` clause.
3227
* The position value indicates the start position of the template of the
3328
* deriving class.

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,12 @@ object ProtoTypes {
180180
{
181181
val mbr = if (privateOK) tp1.member(name) else tp1.nonPrivateMember(name)
182182
def qualifies(m: SingleDenotation) =
183-
memberProto.isRef(defn.UnitClass) ||
184-
tp1.isValueType && compat.normalizedCompatible(NamedType(tp1, name, m), memberProto, keepConstraint)
185-
// Note: can't use `m.info` here because if `m` is a method, `m.info`
186-
// loses knowledge about `m`'s default arguments.
183+
val isAccessible = !m.symbol.exists || m.symbol.isAccessibleFrom(tp1, superAccess = true)
184+
isAccessible
185+
&& (memberProto.isRef(defn.UnitClass)
186+
|| tp1.isValueType && compat.normalizedCompatible(NamedType(tp1, name, m), memberProto, keepConstraint))
187+
// Note: can't use `m.info` here because if `m` is a method, `m.info`
188+
// loses knowledge about `m`'s default arguments.
187189
mbr match { // hasAltWith inlined for performance
188190
case mbr: SingleDenotation => mbr.exists && qualifies(mbr)
189191
case _ => mbr hasAltWith qualifies

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,9 @@ trait TypeAssigner {
173173
/** The type of the selection in `tree`, where `qual1` is the typed qualifier part.
174174
* The selection type is additionally checked for accessibility.
175175
*/
176-
def accessibleSelectionType(tree: untpd.RefTree, qual1: Tree)(using Context): Type = {
176+
def accessibleSelectionType(tree: untpd.RefTree, qual1: Tree)(using Context): Type =
177177
val ownType = selectionType(tree, qual1)
178-
if (tree.hasAttachment(desugar.SuppressAccessCheck)) ownType
179-
else ensureAccessible(ownType, qual1.isInstanceOf[Super], tree.srcPos)
180-
}
178+
ensureAccessible(ownType, qual1.isInstanceOf[Super], tree.srcPos)
181179

182180
/** Type assignment method. Each method takes as parameters
183181
* - an untpd.Tree to which it assigns a type,

tests/neg/overloading-specifity.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ object Test extends App {
2323
def foo[T]: Show[T] = new Show[T](2)
2424
}
2525

26-
assert(a.foo[Int].i == 2) // error: no implicit argument of type Test.Context was found for parameter ctx
26+
val b = a.foo[Int] // error: no implicit argument of type context found
27+
assert(b.i == 1) // error
2728
}

tests/pos/i10311.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
object Module {
2+
class MyInt(private val x: Int, private val y: Int)
3+
object MyInt {
4+
implicit class Ops(self: MyInt) extends AnyVal {
5+
def x: Int = self.x
6+
}
7+
extension (self: MyInt) def y: Int = self.y
8+
}
9+
}
10+
object test:
11+
import Module._
12+
13+
val a = new MyInt(42, 43)
14+
val b = a.x
15+
val c = a.y
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Shows that overloading resolution does not test implicits to decide
2+
// applicability. A best alternative is picked first, and then implicits
3+
// are searched for this one.
4+
case class Show[T](val i: Int)
5+
class Show1[T](i: Int) extends Show[T](i)
6+
7+
class Generic
8+
object Generic {
9+
implicit val gen: Generic = new Generic
10+
implicit def showGen[T](implicit gen: Generic): Show[T] = new Show[T](2)
11+
}
12+
13+
object Test extends App {
14+
trait Context
15+
//given ctx as Context
16+
17+
object a {
18+
def foo[T](implicit gen: Generic): Show[T] = new Show[T](1)
19+
def foo[T](implicit gen: Generic, ctx: Context): Show1[T] = new Show1[T](2)
20+
}
21+
object b {
22+
def foo[T](implicit gen: Generic): Show[T] = new Show[T](1)
23+
def foo[T]: Show[T] = new Show[T](2)
24+
}
25+
26+
assert(a.foo[Int].i == 1) // error: no implicit argument of type Test.Context was found for parameter ctx
27+
}

0 commit comments

Comments
 (0)