Skip to content

Commit 5846f0e

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

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
@@ -1418,12 +1418,12 @@ object desugar {
14181418
* def $anonfun(params) = body
14191419
* Closure($anonfun)
14201420
*/
1421-
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree | Null = null, isContextual: Boolean, span: Span)(using Context): Block =
1421+
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree | Null = null, span: Span)(using Context): Block =
14221422
Block(
14231423
DefDef(nme.ANON_FUN, params :: Nil, if (tpt == null) TypeTree() else tpt, body)
14241424
.withSpan(span)
14251425
.withMods(synthetic | Artifact),
1426-
Closure(Nil, Ident(nme.ANON_FUN), if (isContextual) ContextualEmptyTree else EmptyTree))
1426+
Closure(Nil, Ident(nme.ANON_FUN), EmptyTree))
14271427

14281428
/** If `nparams` == 1, expand partial function
14291429
*

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,7 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
417417
case Closure(_, meth, _) => true
418418
case Block(Nil, expr) => isContextualClosure(expr)
419419
case Block(DefDef(nme.ANON_FUN, params :: _, _, _) :: Nil, cl: Closure) =>
420-
if params.isEmpty then
421-
cl.tpt.eq(untpd.ContextualEmptyTree) || defn.isContextFunctionType(cl.tpt.typeOpt)
422-
else
423-
isUsingClause(params)
420+
isUsingClause(params)
424421
case _ => false
425422
}
426423

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
@@ -1633,7 +1633,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16331633
)
16341634
cpy.ValDef(param)(tpt = paramTpt)
16351635
if isErased then param0.withAddedFlags(Flags.Erased) else param0
1636-
desugared = desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual, tree.span)
1636+
desugared = desugar.makeClosure(inferredParams, fnBody, resultTpt, tree.span)
16371637

16381638
typed(desugared, pt)
16391639
.showing(i"desugared fun $tree --> $desugared with pt = $pt", typr)
@@ -1669,9 +1669,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16691669
errorTree(tree,
16701670
em"""cannot turn method type $mt into closure
16711671
|because it has internal parameter dependencies""")
1672-
else if ((tree.tpt `eq` untpd.ContextualEmptyTree) && mt.paramNames.isEmpty)
1673-
// Note implicitness of function in target type since there are no method parameters that indicate it.
1674-
TypeTree(defn.FunctionOf(Nil, mt.resType, isContextual = true))
16751672
else if hasCaptureConversionArg(mt.resType) then
16761673
errorTree(tree,
16771674
em"""cannot turn method type $mt into closure
@@ -3106,6 +3103,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
31063103
val ifpt = defn.asContextFunctionType(pt)
31073104
val result =
31083105
if ifpt.exists
3106+
&& defn.functionArity(ifpt) > 0 // ContextFunction0 is only used after ElimByName
31093107
&& xtree.isTerm
31103108
&& !untpd.isContextualClosure(xtree)
31113109
&& !ctx.mode.is(Mode.Pattern)

0 commit comments

Comments
 (0)