Skip to content

Commit 5e774d7

Browse files
committed
Add modifier to NonEmptyFunction and replace ImplicitFunction
1 parent 85f9a70 commit 5e774d7

File tree

4 files changed

+12
-29
lines changed

4 files changed

+12
-29
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ object desugar {
825825

826826
def makeImplicitFunction(formals: List[Type], body: Tree)(implicit ctx: Context): Tree = {
827827
val params = makeImplicitParameters(formals.map(TypeTree))
828-
new ImplicitFunction(params, body)
828+
new NonEmptyFunction(params, body, Modifiers(Implicit))
829829
}
830830

831831
/** Add annotation to tree:

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,14 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
5050
*/
5151
case class InterpolatedString(id: TermName, segments: List[Tree]) extends TermTree
5252

53-
/** An function type */
53+
/** A function type */
5454
case class Function(args: List[Tree], body: Tree) extends Tree {
5555
override def isTerm = body.isTerm
5656
override def isType = body.isType
5757
}
5858

59-
/** An function type that should have non empty args */
60-
abstract class NonEmptyFunction(args: List[Tree], body: Tree) extends Function(args, body)
61-
62-
/** An implicit function type */
63-
class ImplicitFunction(args: List[Tree], body: Tree) extends NonEmptyFunction(args, body) {
64-
override def toString = s"ImplicitFunction($args, $body)"
65-
}
66-
67-
/** An function type with unused arguments */
68-
class UnusedFunction(args: List[Tree], body: Tree) extends NonEmptyFunction(args, body) {
69-
override def toString = s"UnusedFunction($args, $body)"
70-
}
71-
72-
/** An implicit function type with unused arguments */
73-
class UnusedImplicitFunction(args: List[Tree], body: Tree) extends NonEmptyFunction(args, body) {
74-
override def toString = s"UnusedImplicitFunction($args, $body)"
75-
}
59+
/** A function type that should have non empty args */
60+
class NonEmptyFunction(args: List[Tree], body: Tree, val mods: Modifiers) extends Function(args, body)
7661

7762
/** A function created from a wildcard expression
7863
* @param placeHolderParams a list of definitions of synthetic parameters

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,7 @@ object Parsers {
727727
def functionRest(params: List[Tree]): Tree =
728728
atPos(start, accept(ARROW)) {
729729
val t = typ()
730-
if (imods.is(Implicit) && imods.is(Unused)) new UnusedImplicitFunction(params, t)
731-
else if (imods.is(Implicit)) new ImplicitFunction(params, t)
732-
else if (imods.is(Unused)) new UnusedFunction(params, t)
730+
if (imods.is(Implicit) || imods.is(Unused)) new NonEmptyFunction(params, t, imods)
733731
else Function(params, t)
734732
}
735733
def funArgTypesRest(first: Tree, following: () => Tree) = {
@@ -790,7 +788,7 @@ object Parsers {
790788
case ARROW => functionRest(t :: Nil)
791789
case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t
792790
case _ =>
793-
if (imods.is(Implicit) && !t.isInstanceOf[ImplicitFunction])
791+
if (imods.is(Implicit) && !t.isInstanceOf[NonEmptyFunction])
794792
syntaxError("Types with implicit keyword can only be function types", Position(start, start + nme.IMPLICITkw.asSimpleName.length))
795793
t
796794
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -761,12 +761,12 @@ class Typer extends Namer
761761
def typedFunctionType(tree: untpd.Function, pt: Type)(implicit ctx: Context) = {
762762
val untpd.Function(args, body) = tree
763763
val (isImplicit, isUnused) = tree match {
764-
case _: untpd.NonEmptyFunction if args.isEmpty =>
765-
ctx.error(FunctionTypeNeedsNonEmptyParameterList(), tree.pos)
766-
(false, false)
767-
case _: untpd.UnusedImplicitFunction => (true, true)
768-
case _: untpd.ImplicitFunction => (true, false)
769-
case _: untpd.UnusedFunction => (false, true)
764+
case tree: untpd.NonEmptyFunction =>
765+
if (args.nonEmpty) (tree.mods.is(Implicit), tree.mods.is(Unused))
766+
else {
767+
ctx.error(FunctionTypeNeedsNonEmptyParameterList(), tree.pos)
768+
(false, false)
769+
}
770770
case _ => (false, false)
771771
}
772772
val funCls = defn.FunctionClass(args.length, isImplicit, isUnused)

0 commit comments

Comments
 (0)