From 054251ea5c747e5d6e678d39131b298c2355c53d Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Tue, 24 Sep 2024 16:47:13 +0200 Subject: [PATCH] Hide context bounds expansion for poly functions under modularity feature --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 6 ++++-- compiler/src/dotty/tools/dotc/typer/Typer.scala | 3 ++- tests/pos/contextbounds-for-poly-functions.scala | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 3ed7442cf50f..f51d4ffd3bc7 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -68,7 +68,7 @@ object Parsers { def acceptsVariance = this == Class || this == CaseClass || this == Hk def acceptsCtxBounds = - !(this == Hk) + !(this == Type || this == Hk) def acceptsWildcard = this == Type || this == Hk @@ -3452,7 +3452,9 @@ object Parsers { else ident().toTypeName val hkparams = typeParamClauseOpt(ParamOwner.Hk) val bounds = - if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name) else typeBounds() + if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name) + else if in.featureEnabled(Feature.modularity) && paramOwner == ParamOwner.Type then typeAndCtxBounds(name) + else typeBounds() TypeDef(name, lambdaAbstract(hkparams, bounds)).withMods(mods) } } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index bf55103aa7a1..4df9e85044b7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1930,7 +1930,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer def typedPolyFunction(tree: untpd.PolyFunction, pt: Type)(using Context): Tree = val tree1 = desugar.normalizePolyFunction(tree) - val tree2 = desugar.expandPolyFunctionContextBounds(tree1) + val tree2 = if Feature.enabled(Feature.modularity) then desugar.expandPolyFunctionContextBounds(tree1) + else tree1 if (ctx.mode is Mode.Type) typed(desugar.makePolyFunctionType(tree2), pt) else typedPolyFunctionValue(tree2, pt) diff --git a/tests/pos/contextbounds-for-poly-functions.scala b/tests/pos/contextbounds-for-poly-functions.scala index 6a3ec9935a65..c293fd0d9780 100644 --- a/tests/pos/contextbounds-for-poly-functions.scala +++ b/tests/pos/contextbounds-for-poly-functions.scala @@ -1,7 +1,6 @@ import scala.language.experimental.modularity import scala.language.future - trait Ord[X]: def compare(x: X, y: X): Int