Skip to content

Commit e78f449

Browse files
committed
Move relaxed context to a function
1 parent 939ec21 commit e78f449

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,9 @@ object Contexts {
712712

713713
def withNotNullInfos(infos: List[NotNullInfo]): Context =
714714
if c.notNullInfos eq infos then c else c.fresh.setNotNullInfos(infos)
715+
716+
def relaxedOverrideContext: Context =
717+
c.withModeBits(c.mode &~ Mode.SafeNulls | Mode.RelaxedOverriding)
715718
end ops
716719

717720
// TODO: Fix issue when converting ModeChanges and FreshModeChanges to extension givens

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,7 @@ object Types {
11121112
*/
11131113
def matches(that: Type)(using Context): Boolean = {
11141114
record("matches")
1115-
val overrideCtx = if ctx.explicitNulls
1116-
then ctx.retractMode(Mode.SafeNulls).addMode(Mode.RelaxedOverriding)
1117-
else ctx
1115+
val overrideCtx = if ctx.explicitNulls then ctx.relaxedOverrideContext else ctx
11181116
TypeComparer.matchesType(this, that, relaxed = !ctx.phase.erasedTypes)(using overrideCtx)
11191117
}
11201118

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ object OverridingPairs:
219219
// releaxed override check for explicit nulls if one of the symbols is Java defined,
220220
// force `Null` to be a subtype of non-primitive value types during override checking.
221221
val overrideCtx = if ctx.explicitNulls && (member.is(JavaDefined) || other.is(JavaDefined))
222-
then ctx.retractMode(Mode.SafeNulls).addMode(Mode.RelaxedOverriding) else ctx
222+
then ctx.relaxedOverrideContext else ctx
223223
member.name.is(DefaultGetterName) // default getters are not checked for compatibility
224224
|| memberTp.overrides(otherTp,
225225
member.matchNullaryLoosely || other.matchNullaryLoosely || fallBack

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ object ResolveSuper {
115115
// we use relaxed overriding check for explicit nulls if one of the symbols is Java defined.
116116
// This forces `Null` to be a subtype of non-primitive value types during override checking.
117117
val overrideCtx = if ctx.explicitNulls && (sym.is(JavaDefined) || acc.is(JavaDefined))
118-
then ctx.retractMode(Mode.SafeNulls).addMode(Mode.RelaxedOverriding) else ctx
118+
then ctx.relaxedOverrideContext else ctx
119119
if !otherTp.overrides(accTp, matchLoosely = true)(using overrideCtx) then
120120
report.error(IllegalSuperAccessor(base, memberName, targetName, acc, accTp, other.symbol, otherTp), base.srcPos)
121121
bcs = bcs.tail

0 commit comments

Comments
 (0)