From edd6653863af40e0067b00e399da768b61ecc258 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Tue, 14 Jan 2020 12:31:53 +0100 Subject: [PATCH 1/2] Fix #7980: SAM type should check trait parameters --- compiler/src/dotty/tools/dotc/core/Types.scala | 2 +- tests/neg/i7980.scala | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i7980.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index fefe1b5c1cd1..dacf087da426 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -4518,7 +4518,7 @@ object Types { case et: ExprType => true case _ => false } - if (tp.cls.is(Trait) || zeroParams(tp.cls.primaryConstructor.info)) tp // !!! needs to be adapted once traits have parameters + if (zeroParams(tp.cls.primaryConstructor.info)) tp else NoType case tp: AppliedType => zeroParamClass(tp.superType) diff --git a/tests/neg/i7980.scala b/tests/neg/i7980.scala new file mode 100644 index 000000000000..0a7e99f8d0c3 --- /dev/null +++ b/tests/neg/i7980.scala @@ -0,0 +1,7 @@ +trait Evidence[X] + +trait Trait[X : Evidence] + def method(x : X) : X + +given ev : Evidence[Int] = new Evidence[Int]{} +val crash : Trait[Int] = (x: Int) => x // error From 9e98d6ddad93f1a86da2226a7c02173e2fb10df0 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Tue, 14 Jan 2020 14:08:11 +0100 Subject: [PATCH 2/2] Fix check of constructor params `ImplicitFunctionN` does not have constructors --- compiler/src/dotty/tools/dotc/core/Types.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index dacf087da426..e51ad56e8a88 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -4518,7 +4518,9 @@ object Types { case et: ExprType => true case _ => false } - if (zeroParams(tp.cls.primaryConstructor.info)) tp + // `ImplicitFunctionN` does not have constructors + val ctor = tp.cls.primaryConstructor + if (!ctor.exists || zeroParams(ctor.info)) tp else NoType case tp: AppliedType => zeroParamClass(tp.superType)