File tree Expand file tree Collapse file tree 3 files changed +31
-2
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -3749,12 +3749,18 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3749
3749
val ifpt = defn.asContextFunctionType(pt)
3750
3750
val result =
3751
3751
if ifpt.exists
3752
- && defn.functionArity(ifpt) > 0 // ContextFunction0 is only used after ElimByName
3752
+ && ! ctx.isAfterTyper
3753
+ && {
3754
+ // ContextFunction0 is only used after ElimByName
3755
+ val arity = defn.functionArity(ifpt)
3756
+ if arity == 0 then
3757
+ report.error(em " context function types require at least one parameter " , xtree.srcPos)
3758
+ arity > 0
3759
+ }
3753
3760
&& xtree.isTerm
3754
3761
&& ! untpd.isContextualClosure(xtree)
3755
3762
&& ! ctx.mode.is(Mode .Pattern )
3756
3763
&& ! xtree.isInstanceOf [SplicePattern ]
3757
- && ! ctx.isAfterTyper
3758
3764
&& ! ctx.isInlineContext
3759
3765
then
3760
3766
makeContextualFunction(xtree, ifpt)
Original file line number Diff line number Diff line change
1
+ -- Error: tests/neg/i21321.scala:3:42 ----------------------------------------------------------------------------------
2
+ 3 |val v1b: scala.ContextFunction0[String] = () ?=> "x" // error
3
+ | ^^
4
+ | context function literals require at least one formal parameter
5
+ -- Error: tests/neg/i21321.scala:4:8 -----------------------------------------------------------------------------------
6
+ 4 |val v2: () ?=> String = "y" // error // error in parser
7
+ | ^^
8
+ | context function types require at least one parameter
9
+ -- Error: tests/neg/i21321.scala:2:41 ----------------------------------------------------------------------------------
10
+ 2 |val v1: scala.ContextFunction0[String] = "x" // error
11
+ | ^^^
12
+ | context function types require at least one parameter
13
+ -- [E007] Type Mismatch Error: tests/neg/i21321.scala:4:24 -------------------------------------------------------------
14
+ 4 |val v2: () ?=> String = "y" // error // error in parser
15
+ | ^^^
16
+ | Found: ("y" : String)
17
+ | Required: () => String
18
+ |
19
+ | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change
1
+
2
+ val v1 : scala.ContextFunction0 [String ] = " x" // error
3
+ val v1b : scala.ContextFunction0 [String ] = () ?=> " x" // error
4
+ val v2 : () ?=> String = " y" // error // error in parser
You can’t perform that action at this time.
0 commit comments