Skip to content

Commit f5fc096

Browse files
authored
Backport "Refine infoDependsOnPrefix" (#18410)
Backports #18204
2 parents 0597482 + d2a0b3c commit f5fc096

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

+1
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,7 @@ object SymDenotations {
11961196
isOneOf(EffectivelyFinalFlags)
11971197
|| is(Inline, butNot = Deferred)
11981198
|| is(JavaDefinedVal, butNot = Method)
1199+
|| isConstructor
11991200
|| !owner.isExtensibleClass
12001201

12011202
/** A class is effectively sealed if has the `final` or `sealed` modifier, or it

compiler/src/dotty/tools/dotc/core/Types.scala

+1
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,7 @@ object Types {
25372537
(symd.isAbstractType
25382538
|| symd.isTerm
25392539
&& !symd.flagsUNSAFE.isOneOf(Module | Final | Param)
2540+
&& !symd.isConstructor
25402541
&& !symd.maybeOwner.isEffectivelyFinal)
25412542
&& prefix.sameThis(symd.maybeOwner.thisType)
25422543
&& refines(givenSelfTypeOrCompleter(prefix.cls), symd.name)

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ object TreeChecker {
544544
val TypeDef(_, impl @ Template(constr, _, _, _)) = cdef: @unchecked
545545
assert(cdef.symbol == cls)
546546
assert(impl.symbol.owner == cls)
547-
assert(constr.symbol.owner == cls)
547+
assert(constr.symbol.owner == cls, i"constr ${constr.symbol} in $cdef has wrong owner; should be $cls but is ${constr.symbol.owner}")
548548
assert(cls.primaryConstructor == constr.symbol, i"mismatch, primary constructor ${cls.primaryConstructor}, in tree = ${constr.symbol}")
549549
checkOwner(impl)
550550
checkOwner(impl.constr)

compiler/src/dotty/tools/dotc/transform/init/Util.scala

+2-4
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ object Util:
7575
case _ =>
7676
None
7777

78-
def resolve(cls: ClassSymbol, sym: Symbol)(using Context): Symbol = log("resove " + cls + ", " + sym, printer, (_: Symbol).show) {
79-
if (sym.isEffectivelyFinal || sym.isConstructor) sym
78+
def resolve(cls: ClassSymbol, sym: Symbol)(using Context): Symbol = log("resove " + cls + ", " + sym, printer, (_: Symbol).show):
79+
if sym.isEffectivelyFinal then sym
8080
else sym.matchingMember(cls.appliedRef)
81-
}
82-
8381

8482
extension (sym: Symbol)
8583
def hasSource(using Context): Boolean = !sym.defTree.isEmpty

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ class RefChecks extends MiniPhase { thisPhase =>
16891689
// if (settings.warnNullaryUnit)
16901690
// checkNullaryMethodReturnType(sym)
16911691
// if (settings.warnInaccessible) {
1692-
// if (!sym.isConstructor && !sym.isEffectivelyFinal && !sym.isSynthetic)
1692+
// if (!sym.isEffectivelyFinal && !sym.isSynthetic)
16931693
// checkAccessibilityOfReferencedTypes(tree)
16941694
// }
16951695
// tree match {

tests/pos/i18160/Test_2.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class SynchronizedReevaluation
2+
class SynchronizedReevaluationApi[Api <: RescalaInterface](val api: Api){
3+
import api._
4+
5+
def SynchronizedReevaluation[A](evt: Event[A])(implicit
6+
turnSource: CreationTicket
7+
): (SynchronizedReevaluation, Event[A]) = {
8+
val sync = new SynchronizedReevaluation
9+
(sync, evt.map(identity)(turnSource))
10+
}
11+
}

tests/pos/i18160/repro_1.scala

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
object core {
2+
final class CreationTicket[State[_]]
3+
}
4+
5+
trait ReadAs[S[_], +A] { type State[V] = S[V] }
6+
7+
trait EventCompatBundle {
8+
bundle: Operators =>
9+
10+
trait EventCompat[+T] extends ReadAs[State, Option[T]] {
11+
selfType: Event[T] =>
12+
final inline def map[B](inline expression: T => B)(implicit ticket: CreationTicket): Event[B] = ???
13+
}
14+
}
15+
16+
trait EventBundle extends EventCompatBundle { self: Operators =>
17+
trait Event[+T] extends EventCompat[T]:
18+
final override type State[V] = self.State[V]
19+
}
20+
trait Operators extends EventBundle {
21+
type State[_]
22+
type CreationTicket = core.CreationTicket[State]
23+
}
24+
trait RescalaInterface extends Operators
25+

0 commit comments

Comments
 (0)