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 @@ -3751,12 +3751,18 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
37513751          val  ifpt  =  defn.asContextFunctionType(pt)
37523752          val  result  = 
37533753            if  ifpt.exists
3754-               &&  defn.functionArity(ifpt) >  0  //  ContextFunction0 is only used after ElimByName
3754+               &&  ! ctx.isAfterTyper
3755+               &&  {
3756+                 //  ContextFunction0 is only used after ElimByName
3757+                 val  arity  =  defn.functionArity(ifpt)
3758+                 if  arity ==  0  then 
3759+                   report.error(em " context function types require at least one parameter " , xtree.srcPos)
3760+                 arity >  0 
3761+               }
37553762              &&  xtree.isTerm
37563763              &&  ! untpd.isContextualClosure(xtree)
37573764              &&  ! ctx.mode.is(Mode .Pattern )
37583765              &&  ! xtree.isInstanceOf [SplicePattern ]
3759-               &&  ! ctx.isAfterTyper
37603766              &&  ! ctx.isInlineContext
37613767            then 
37623768              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