Skip to content

Commit 871e23f

Browse files
committed
Drop vestigial support for parameterless contextual functions
This was dropped from the syntax, so this isn't needed anymore.
1 parent 9af339b commit 871e23f

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,12 +1434,12 @@ object desugar {
14341434
* def $anonfun(params) = body
14351435
* Closure($anonfun)
14361436
*/
1437-
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree | Null = null, isContextual: Boolean, span: Span)(using Context): Block =
1437+
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree | Null = null, span: Span)(using Context): Block =
14381438
Block(
14391439
DefDef(nme.ANON_FUN, params :: Nil, if (tpt == null) TypeTree() else tpt, body)
14401440
.withSpan(span)
14411441
.withMods(synthetic | Artifact),
1442-
Closure(Nil, Ident(nme.ANON_FUN), if (isContextual) ContextualEmptyTree else EmptyTree))
1442+
Closure(Nil, Ident(nme.ANON_FUN), EmptyTree))
14431443

14441444
/** If `nparams` == 1, expand partial function
14451445
*

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,7 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
420420
case Closure(_, meth, _) => true
421421
case Block(Nil, expr) => isContextualClosure(expr)
422422
case Block(DefDef(nme.ANON_FUN, params :: _, _, _) :: Nil, cl: Closure) =>
423-
if params.isEmpty then
424-
cl.tpt.eq(untpd.ContextualEmptyTree) || defn.isContextFunctionType(cl.tpt.typeOpt)
425-
else
426-
isUsingClause(params)
423+
isUsingClause(params)
427424
case _ => false
428425
}
429426

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,6 @@ object Trees {
11921192

11931193
@sharable val EmptyTree: Thicket = genericEmptyTree
11941194
@sharable val EmptyValDef: ValDef = genericEmptyValDef
1195-
@sharable val ContextualEmptyTree: Thicket = new EmptyTree() // an empty tree marking a contextual closure
11961195

11971196
// ----- Auxiliary creation methods ------------------
11981197

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,12 @@ object NameOps {
236236
*/
237237
def isPlainFunction(using Context): Boolean = functionArity >= 0
238238

239-
/** Is a function name that contains `mustHave` as a substring */
240-
private def isSpecificFunction(mustHave: String)(using Context): Boolean =
239+
/** Is a function name that contains `mustHave` as a substring
240+
* and has arity `minArity` or greater.
241+
*/
242+
private def isSpecificFunction(mustHave: String, minArity: Int = 0)(using Context): Boolean =
241243
val suffixStart = functionSuffixStart
242-
isFunctionPrefix(suffixStart, mustHave) && funArity(suffixStart) >= 0
244+
isFunctionPrefix(suffixStart, mustHave) && funArity(suffixStart) >= minArity
243245

244246
def isContextFunction(using Context): Boolean = isSpecificFunction("Context")
245247
def isImpureFunction(using Context): Boolean = isSpecificFunction("Impure")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,7 @@ object Parsers {
15111511
TermLambdaTypeTree(params.asInstanceOf[List[ValDef]], resultType)
15121512
else if imods.isOneOf(Given | Impure) || erasedArgs.contains(true) then
15131513
if imods.is(Given) && params.isEmpty then
1514+
imods &~= Given
15141515
syntaxError(em"context function types require at least one parameter", paramSpan)
15151516
FunctionWithMods(params, resultType, imods, erasedArgs.toList)
15161517
else if !ctx.settings.YkindProjector.isDefault then

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16251625
)
16261626
cpy.ValDef(param)(tpt = paramTpt)
16271627
if isErased then param0.withAddedFlags(Flags.Erased) else param0
1628-
desugared = desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual, tree.span)
1628+
desugared = desugar.makeClosure(inferredParams, fnBody, resultTpt, tree.span)
16291629

16301630
typed(desugared, pt)
16311631
.showing(i"desugared fun $tree --> $desugared with pt = $pt", typr)
@@ -1661,9 +1661,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16611661
errorTree(tree,
16621662
em"""cannot turn method type $mt into closure
16631663
|because it has internal parameter dependencies""")
1664-
else if ((tree.tpt `eq` untpd.ContextualEmptyTree) && mt.paramNames.isEmpty)
1665-
// Note implicitness of function in target type since there are no method parameters that indicate it.
1666-
TypeTree(defn.FunctionOf(Nil, mt.resType, isContextual = true))
16671664
else if hasCaptureConversionArg(mt.resType) then
16681665
errorTree(tree,
16691666
em"""cannot turn method type $mt into closure
@@ -3104,6 +3101,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
31043101
val ifpt = defn.asContextFunctionType(pt)
31053102
val result =
31063103
if ifpt.exists
3104+
&& defn.functionArity(ifpt) > 0 // ContextFunction0 is only used after ElimByName
31073105
&& xtree.isTerm
31083106
&& !untpd.isContextualClosure(xtree)
31093107
&& !ctx.mode.is(Mode.Pattern)

0 commit comments

Comments
 (0)