Skip to content

Commit 9940c6c

Browse files
committed
Keep track of extension method rhs in Mode
1 parent 92c7c01 commit 9940c6c

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,7 @@ object Mode {
112112

113113
/** Are we in a quote in a pattern? */
114114
val QuotedPattern: Mode = newMode(25, "QuotedPattern")
115+
116+
/** Are we typechecking the rhs of an extension method? */
117+
val InExtensionMethod: Mode = newMode(26, "InExtensionMethod")
115118
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,8 @@ class Namer { typer: Typer =>
13531353
def dealiasIfUnit(tp: Type) = if (tp.isRef(defn.UnitClass)) defn.UnitType else tp
13541354

13551355
var rhsCtx = ctx.fresh.addMode(Mode.InferringReturnType)
1356-
if (sym.isInlineMethod) rhsCtx = rhsCtx.addMode(Mode.InlineableBody)
1356+
if sym.isInlineMethod then rhsCtx = rhsCtx.addMode(Mode.InlineableBody)
1357+
if sym.is(ExtensionMethod) then rhsCtx = rhsCtx.addMode(Mode.InExtensionMethod)
13571358
if (typeParams.nonEmpty) {
13581359
// we'll be typing an expression from a polymorphic definition's body,
13591360
// so we must allow constraining its type parameters

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,8 @@ class Typer extends Namer
19771977
}
19781978
}
19791979

1980-
if (sym.isInlineMethod) rhsCtx.addMode(Mode.InlineableBody)
1980+
if sym.isInlineMethod then rhsCtx.addMode(Mode.InlineableBody)
1981+
if sym.is(ExtensionMethod) then rhsCtx.addMode(Mode.InExtensionMethod)
19811982
val rhs1 = PrepareInlineable.dropInlineIfError(sym,
19821983
if sym.isScala2Macro then typedScala2MacroBody(ddef.rhs)(using rhsCtx)
19831984
else typedExpr(ddef.rhs, tpt1.tpe.widenExpr)(using rhsCtx))

0 commit comments

Comments
 (0)