Skip to content

Commit

Permalink
Fix overriding check
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Dec 1, 2024
1 parent 1fb05b2 commit 82c5512
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
* The info of these symbols is made fluid.
*/
def isPreCC(sym: Symbol)(using Context): Boolean =
// TODO: check type members as well
sym.isTerm && sym.maybeOwner.isClass
&& !sym.is(Module)
&& !sym.owner.is(CaptureChecked)
Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import config.MigrationVersion
import config.Printers.refcheck
import reporting.*
import Constants.Constant
import cc.stripCapturing

object RefChecks {
import tpd.*
Expand Down Expand Up @@ -83,8 +84,10 @@ object RefChecks {
* This one used to succeed only if forwarding parameters is on.
* (Forwarding tends to hide problems by binding parameter names).
*/

private def upwardsThisType(cls: Symbol)(using Context) = cls.info match {
case ClassInfo(_, _, _, _, tp: Type) if (tp ne cls.typeRef) && !cls.isOneOf(FinalOrModuleClass) =>
case ClassInfo(_, _, _, _, tp: Type) if (tp.stripCapturing ne cls.typeRef) && !cls.isOneOf(FinalOrModuleClass) =>
// println(i"upwardsThisType($cls) = ${cls.typeRef}, ne $tp")
SkolemType(cls.appliedRef).withName(nme.this_)
case _ =>
cls.thisType
Expand Down Expand Up @@ -439,7 +442,7 @@ object RefChecks {
val (mtp, otp) = if compareTypes then (memberTp(self), otherTp(self)) else (NoType, NoType)
OverrideError(core, self, member, other, mtp, otp)

def compatTypes(memberTp: Type, otherTp: Type): Boolean =
def compatTypes(memberTp: Type, otherTp: Type): Boolean = // race.force(i"compatTypes $memberTp <:< $otherTp"):
try
isOverridingPair(member, memberTp, other, otherTp,
fallBack = warnOnMigration(
Expand Down
10 changes: 1 addition & 9 deletions tests/neg-custom-args/captures/i21868b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ class Concrete4(io: IO^) extends Abstract2(io):
type C = CapSet
def f(file: File) = ()

// TODO: Should be an error
class Concrete5(io1: IO^, io2: IO^) extends Abstract2(io1):
// Similar to Concrete8, this type member should have overriding error.
// Parent class is Abstract2 { val io = Concrete5.this.io1 }
// Abstract2.this.C >: CapSet <: CapSet^{Concrete5.this.io1}
// Concrete5.this.C = CapSet^{Concrete5.this.io2}
// CapSet^{Concrete5.this.io2} !<:< CapSet^{Concrete5.this.io1}
// Hence, Concrete5.this.C !<:< Abstract2.this.C
type C = CapSet^{io2}
type C = CapSet^{io2} // error
def f(file: File^{io2}) = ()

trait Abstract3[X^]:
Expand All @@ -53,5 +46,4 @@ class Concrete7(io1: IO^, io2: IO^) extends Abstract3[CapSet^{io1}]:
def f(file: File^{io2}) = ()

class Concrete8(io1: IO^, io2: IO^) extends Abstract3[CapSet^{io1}]:
type C = CapSet^{io1}
def f(file: File^{io2}) = () // error

0 comments on commit 82c5512

Please sign in to comment.