Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b099e00

Browse files
Explain no expansion of ContextFunction0
1 parent ca400bd commit b099e00

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

‎compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3749,12 +3749,18 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
37493749
val ifpt = defn.asContextFunctionType(pt)
37503750
val result =
37513751
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+
}
37533760
&& xtree.isTerm
37543761
&& !untpd.isContextualClosure(xtree)
37553762
&& !ctx.mode.is(Mode.Pattern)
37563763
&& !xtree.isInstanceOf[SplicePattern]
3757-
&& !ctx.isAfterTyper
37583764
&& !ctx.isInlineContext
37593765
then
37603766
makeContextualFunction(xtree, ifpt)

‎tests/neg/i21321.check

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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`

‎tests/neg/i21321.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /