File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -740,7 +740,10 @@ class Definitions {
740
740
lazy val TupleType = mkArityArray(" scala.Tuple" , MaxTupleArity , 2 )
741
741
742
742
def FunctionClass (n : Int , isImplicit : Boolean = false )(implicit ctx : Context ) =
743
- if (isImplicit) ctx.requiredClass(" scala.ImplicitFunction" + n.toString)
743
+ if (isImplicit) {
744
+ require(n > 0 )
745
+ ctx.requiredClass(" scala.ImplicitFunction" + n.toString)
746
+ }
744
747
else if (n <= MaxImplementedFunctionArity ) FunctionClassPerRun ()(ctx)(n)
745
748
else ctx.requiredClass(" scala.Function" + n.toString)
746
749
@@ -773,12 +776,12 @@ class Definitions {
773
776
774
777
/** Is a function class.
775
778
* - FunctionN for N >= 0
776
- * - ImplicitFunctionN for N >= 0
779
+ * - ImplicitFunctionN for N > 0
777
780
*/
778
781
def isFunctionClass (cls : Symbol ) = scalaClassName(cls).isFunction
779
782
780
783
/** Is an implicit function class.
781
- * - ImplicitFunctionN for N >= 0
784
+ * - ImplicitFunctionN for N > 0
782
785
*/
783
786
def isImplicitFunctionClass (cls : Symbol ) = scalaClassName(cls).isImplicitFunction
784
787
@@ -790,7 +793,7 @@ class Definitions {
790
793
791
794
/** Is a synthetic function class
792
795
* - FunctionN for N > 22
793
- * - ImplicitFunctionN for N >= 0
796
+ * - ImplicitFunctionN for N > 0
794
797
*/
795
798
def isSyntheticFunctionClass (cls : Symbol ) = scalaClassName(cls).isSyntheticFunction
796
799
Original file line number Diff line number Diff line change @@ -687,7 +687,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
687
687
def typedFunction (tree : untpd.Function , pt : Type )(implicit ctx : Context ) = track(" typedFunction" ) {
688
688
val untpd .Function (args, body) = tree
689
689
if (ctx.mode is Mode .Type ) {
690
- val funCls = defn.FunctionClass (args.length, tree.isInstanceOf [untpd.ImplicitFunction ])
690
+ val isImplicit = tree match {
691
+ case _ : untpd.ImplicitFunction =>
692
+ if (args.length == 0 ) {
693
+ ctx.error(i " implicit function type needs non-empty parameter list " , tree.pos)
694
+ false
695
+ }
696
+ else true
697
+ case _ => false
698
+ }
699
+ val funCls = defn.FunctionClass (args.length, isImplicit)
691
700
typed(cpy.AppliedTypeTree (tree)(
692
701
untpd.TypeTree (funCls.typeRef), args :+ body), pt)
693
702
}
Original file line number Diff line number Diff line change
1
+ object Foo {
2
+ type X = implicit () => Int // error: implicit function needs parameters
3
+ def ff : X = () // error: found: Unit, expected: X
4
+ }
You can’t perform that action at this time.
0 commit comments