From 871a87eaa8c9cb181a7be721f305b861ae1c96c5 Mon Sep 17 00:00:00 2001 From: Saurabh Rawat Date: Tue, 25 Dec 2018 20:54:23 +0530 Subject: [PATCH 1/2] Fix #5640 Typer crash on 0 arity tuple --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 2 +- tests/neg/i5640.scala | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i5640.scala diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 0c44a640ec25..25cb6bb0d2a9 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -920,8 +920,8 @@ object desugar { assert(arity <= Definitions.MaxTupleArity) def tupleTypeRef = defn.TupleType(arity) if (arity == 1) ts.head - else if (ctx.mode is Mode.Type) AppliedTypeTree(ref(tupleTypeRef), ts) else if (arity == 0) unitLiteral + else if (ctx.mode is Mode.Type) AppliedTypeTree(ref(tupleTypeRef), ts) 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 From 2690241696364c86bb719719a117ce10ecc8655b Mon Sep 17 00:00:00 2001 From: Saurabh Rawat Date: Fri, 4 Jan 2019 15:45:02 +0530 Subject: [PATCH 2/2] address review comments --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 25cb6bb0d2a9..0dc9c1946d67 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -920,7 +920,8 @@ object desugar { assert(arity <= Definitions.MaxTupleArity) def tupleTypeRef = defn.TupleType(arity) if (arity == 1) ts.head - else if (arity == 0) unitLiteral + 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 Apply(ref(tupleTypeRef.classSymbol.companionModule.termRef), ts) }