File tree 4 files changed +31
-12
lines changed
compiler/src/dotty/tools/dotc 4 files changed +31
-12
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 @@ -156,33 +156,36 @@ object NameOps {
156
156
157
157
/** Is a synthetic function name
158
158
* - N for FunctionN
159
- * - N for ImplicitFunctionN
159
+ * - N for ImplicitFunctionN (N >= 1)
160
160
* - (-1) otherwise
161
161
*/
162
162
def functionArity : Int =
163
- functionArityFor(str.Function ) max functionArityFor(str.ImplicitFunction )
163
+ functionArityFor(str.Function ) max {
164
+ val n = functionArityFor(str.ImplicitFunction )
165
+ if (n == 0 ) - 1 else n
166
+ }
164
167
165
168
/** Is a function name
166
169
* - FunctionN for N >= 0
167
- * - ImplicitFunctionN for N >= 0
170
+ * - ImplicitFunctionN for N >= 1
168
171
* - false otherwise
169
172
*/
170
173
def isFunction : Boolean = functionArity >= 0
171
174
172
175
/** Is a implicit function name
173
- * - ImplicitFunctionN for N >= 0
176
+ * - ImplicitFunctionN for N >= 1
174
177
* - false otherwise
175
178
*/
176
- def isImplicitFunction : Boolean = functionArityFor(str.ImplicitFunction ) >= 0
179
+ def isImplicitFunction : Boolean = functionArityFor(str.ImplicitFunction ) >= 1
177
180
178
181
/** Is a synthetic function name
179
182
* - FunctionN for N > 22
180
- * - ImplicitFunctionN for N >= 0
183
+ * - ImplicitFunctionN for N >= 1
181
184
* - false otherwise
182
185
*/
183
186
def isSyntheticFunction : Boolean = {
184
187
functionArityFor(str.Function ) > MaxImplementedFunctionArity ||
185
- functionArityFor(str.ImplicitFunction ) >= 0
188
+ functionArityFor(str.ImplicitFunction ) >= 1
186
189
}
187
190
188
191
/** Parsed function arity for function with some specific prefix */
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