Skip to content

Commit

Permalink
Move relaxed context to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Feb 19, 2022
1 parent 939ec21 commit e78f449
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,9 @@ object Contexts {

def withNotNullInfos(infos: List[NotNullInfo]): Context =
if c.notNullInfos eq infos then c else c.fresh.setNotNullInfos(infos)

def relaxedOverrideContext: Context =
c.withModeBits(c.mode &~ Mode.SafeNulls | Mode.RelaxedOverriding)
end ops

// TODO: Fix issue when converting ModeChanges and FreshModeChanges to extension givens
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,7 @@ object Types {
*/
def matches(that: Type)(using Context): Boolean = {
record("matches")
val overrideCtx = if ctx.explicitNulls
then ctx.retractMode(Mode.SafeNulls).addMode(Mode.RelaxedOverriding)
else ctx
val overrideCtx = if ctx.explicitNulls then ctx.relaxedOverrideContext else ctx
TypeComparer.matchesType(this, that, relaxed = !ctx.phase.erasedTypes)(using overrideCtx)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ object OverridingPairs:
// releaxed override check for explicit nulls if one of the symbols is Java defined,
// force `Null` to be a subtype of non-primitive value types during override checking.
val overrideCtx = if ctx.explicitNulls && (member.is(JavaDefined) || other.is(JavaDefined))
then ctx.retractMode(Mode.SafeNulls).addMode(Mode.RelaxedOverriding) else ctx
then ctx.relaxedOverrideContext else ctx
member.name.is(DefaultGetterName) // default getters are not checked for compatibility
|| memberTp.overrides(otherTp,
member.matchNullaryLoosely || other.matchNullaryLoosely || fallBack
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ object ResolveSuper {
// we use relaxed overriding check for explicit nulls if one of the symbols is Java defined.
// This forces `Null` to be a subtype of non-primitive value types during override checking.
val overrideCtx = if ctx.explicitNulls && (sym.is(JavaDefined) || acc.is(JavaDefined))
then ctx.retractMode(Mode.SafeNulls).addMode(Mode.RelaxedOverriding) else ctx
then ctx.relaxedOverrideContext else ctx
if !otherTp.overrides(accTp, matchLoosely = true)(using overrideCtx) then
report.error(IllegalSuperAccessor(base, memberName, targetName, acc, accTp, other.symbol, otherTp), base.srcPos)
bcs = bcs.tail
Expand Down

0 comments on commit e78f449

Please sign in to comment.