Skip to content

Commit

Permalink
Hide context bounds expansion for poly functions under modularity fea…
Browse files Browse the repository at this point in the history
…ture
  • Loading branch information
KacperFKorban committed Sep 24, 2024
1 parent 44af0d6 commit 054251e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion tests/pos/contextbounds-for-poly-functions.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import scala.language.experimental.modularity
import scala.language.future


trait Ord[X]:
def compare(x: X, y: X): Int

Expand Down

0 comments on commit 054251e

Please sign in to comment.