diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 0c44a640ec25..0dc9c1946d67 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -920,8 +920,9 @@ object desugar { assert(arity <= Definitions.MaxTupleArity) def tupleTypeRef = defn.TupleType(arity) if (arity == 1) ts.head + else if (arity == 0) + if (ctx.mode is Mode.Type) TypeTree(defn.UnitType) else unitLiteral else if (ctx.mode is Mode.Type) AppliedTypeTree(ref(tupleTypeRef), ts) - else if (arity == 0) unitLiteral else Apply(ref(tupleTypeRef.classSymbol.companionModule.termRef), ts) } diff --git a/tests/neg/i5640.scala b/tests/neg/i5640.scala new file mode 100644 index 000000000000..c3a789f8c9bf --- /dev/null +++ b/tests/neg/i5640.scala @@ -0,0 +1,3 @@ +object test { + val foo = (()) => () // error: not a legal formal parameter +} \ No newline at end of file