Skip to content

Commit a1d22d2

Browse files
committed
Refine infoDependsOnPrefix
infoDependsOnPrefix now also considers non-final term members. Before 8d65f19 it only considered abstract types. Constructors were classified as non-final, which caused regression. We now exclude constructors specifically. Maybe we should instead classify them as effectively final. Fixes #18160
1 parent 7ede150 commit a1d22d2

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ object Types {
703703
}
704704
findMember(name, pre, required, excluded)
705705
}
706-
706+
707707
/** The implicit members with given name. If there are none and the denotation
708708
* contains private members, also look for shadowed non-private implicits.
709709
*/
@@ -2583,6 +2583,7 @@ object Types {
25832583
(symd.isAbstractType
25842584
|| symd.isTerm
25852585
&& !symd.flagsUNSAFE.isOneOf(Module | Final | Param)
2586+
&& !symd.isConstructor
25862587
&& !symd.maybeOwner.isEffectivelyFinal)
25872588
&& prefix.sameThis(symd.maybeOwner.thisType)
25882589
&& refines(givenSelfTypeOrCompleter(prefix.cls), symd.name)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ object TreeChecker {
557557
val TypeDef(_, impl @ Template(constr, _, _, _)) = cdef: @unchecked
558558
assert(cdef.symbol == cls)
559559
assert(impl.symbol.owner == cls)
560-
assert(constr.symbol.owner == cls)
560+
assert(constr.symbol.owner == cls, i"constr ${constr.symbol} in $cdef has wrong owner; should be $cls but is ${constr.symbol.owner}")
561561
assert(cls.primaryConstructor == constr.symbol, i"mismatch, primary constructor ${cls.primaryConstructor}, in tree = ${constr.symbol}")
562562
checkOwner(impl)
563563
checkOwner(impl.constr)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3957,7 +3957,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39573957
sym.isConstructor
39583958
|| sym.matchNullaryLoosely
39593959
|| Feature.warnOnMigration(msg, tree.srcPos, version = `3.0`)
3960-
&& {
3960+
&& {
39613961
msg.actions
39623962
.headOption
39633963
.foreach(Rewrites.applyAction)

tests/pos/i18160/Test_2.scala

Lines changed: 11 additions & 0 deletions
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

Lines changed: 25 additions & 0 deletions
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)