Skip to content

Commit 76455c0

Browse files
KacperFKorbanWojciechMazur
authored andcommitted
Hide context bounds expansion for poly functions under modularity feature
[Cherry-picked 134c015]
1 parent c8399ea commit 76455c0

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object Parsers {
6868
def acceptsVariance =
6969
this == Class || this == CaseClass || this == Hk
7070
def acceptsCtxBounds =
71-
!(this == Hk)
71+
!(this == Type || this == Hk)
7272
def acceptsWildcard =
7373
this == Type || this == Hk
7474

@@ -3491,7 +3491,9 @@ object Parsers {
34913491
else ident().toTypeName
34923492
val hkparams = typeParamClauseOpt(ParamOwner.Hk)
34933493
val bounds =
3494-
if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name) else typeBounds()
3494+
if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name)
3495+
else if in.featureEnabled(Feature.modularity) && paramOwner == ParamOwner.Type then typeAndCtxBounds(name)
3496+
else typeBounds()
34953497
TypeDef(name, lambdaAbstract(hkparams, bounds)).withMods(mods)
34963498
}
34973499
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19201920

19211921
def typedPolyFunction(tree: untpd.PolyFunction, pt: Type)(using Context): Tree =
19221922
val tree1 = desugar.normalizePolyFunction(tree)
1923-
val tree2 = desugar.expandPolyFunctionContextBounds(tree1)
1923+
val tree2 = if Feature.enabled(Feature.modularity) then desugar.expandPolyFunctionContextBounds(tree1)
1924+
else tree1
19241925
if (ctx.mode is Mode.Type) typed(desugar.makePolyFunctionType(tree2), pt)
19251926
else typedPolyFunctionValue(tree2, pt)
19261927

tests/pos/contextbounds-for-poly-functions.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import scala.language.experimental.modularity
22
import scala.language.future
33

4-
54
trait Ord[X]:
65
def compare(x: X, y: X): Int
76

0 commit comments

Comments
 (0)