File tree Expand file tree Collapse file tree 4 files changed +32
-3
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 4 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -3745,12 +3745,18 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
37453745 val ifpt = defn.asContextFunctionType(pt)
37463746 val result =
37473747 if ifpt.exists
3748- && defn.functionArity(ifpt) > 0 // ContextFunction0 is only used after ElimByName
3748+ && ! ctx.isAfterTyper
3749+ && {
3750+ // ContextFunction0 is only used after ElimByName
3751+ val arity = defn.functionArity(ifpt)
3752+ if arity == 0 then
3753+ report.error(em " context function types require at least one parameter " , xtree.srcPos)
3754+ arity > 0
3755+ }
37493756 && xtree.isTerm
37503757 && ! untpd.isContextualClosure(xtree)
37513758 && ! ctx.mode.is(Mode .Pattern )
37523759 && ! xtree.isInstanceOf [SplicePattern ]
3753- && ! ctx.isAfterTyper
37543760 && ! ctx.isInlineContext
37553761 then
37563762 makeContextualFunction(xtree, ifpt)
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ val test =
22 (using x : Int ) => x // error // error // error
33
44val f = () ?=> 23 // error
5- val g : ContextFunction0 [Int ] = ??? // ok
5+ val g : ContextFunction0 [Int ] = ??? // error at typer for RHS not expanded
66val h : () ?=> Int = ??? // error
77
88object Example3 extends App {
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