Skip to content

Commit ddb74f4

Browse files
committed
Handle by-name types better
1 parent 243894c commit ddb74f4

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,16 @@ object Parsers {
768768
accept(RPAREN)
769769
if (imods.is(Implicit) || isValParamList || in.token == ARROW) functionRest(ts)
770770
else {
771-
for (t <- ts)
772-
if (t.isInstanceOf[ByNameTypeTree])
773-
syntaxError(ByNameParameterNotSupported())
771+
val ts1 =
772+
for (t <- ts) yield {
773+
t match {
774+
case t@ByNameTypeTree(t1) =>
775+
syntaxError(ByNameParameterNotSupported(t), t.pos)
776+
t1
777+
case _ =>
778+
t
779+
}
780+
}
774781
val tuple = atPos(start) { makeTupleOrParens(ts) }
775782
infixTypeRest(
776783
refinedTypeRest(

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,10 @@ object messages {
696696
}
697697
}
698698

699-
case class ByNameParameterNotSupported()(implicit ctx: Context)
699+
case class ByNameParameterNotSupported(tpe: untpd.TypTree)(implicit ctx: Context)
700700
extends Message(ByNameParameterNotSupportedID) {
701701
val kind = "Syntax"
702-
val msg = "By-name parameter type not allowed here."
702+
val msg = hl"By-name parameter type ${tpe} not allowed here."
703703

704704
val explanation =
705705
hl"""|By-name parameters act like functions that are only evaluated when referenced,

tests/neg/i4373.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,13 @@ object Test {
2121

2222
// Open questions:
2323
type T5 = TypeConstr[_ { type S }] // error
24-
type T5 = TypeConstr[_[Int]] // error
24+
type T6 = TypeConstr[_[Int]] // error
25+
26+
// expression types
27+
type T7 = (=> Int) | (Int => Int) // error
28+
type T8 = (=> Int) & (Int => Int) // error
29+
type T9 = (=> Int) with (Int => Int) // error
30+
type T10 = (Int => Int) | (=> Int) // error
31+
type T11 = (Int => Int) & (=> Int) // error
32+
type T12 = (Int => Int) with (=> Int) // error
2533
}

0 commit comments

Comments
 (0)