From 8433b6fa0e86dfdcd3db31b97844b14d65e45359 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Mon, 8 Feb 2016 18:24:43 -0800 Subject: Treat `Function` literals uniformly, expecting SAM or FunctionN. They both compile to INDY/MetaLambdaFactory, except when they occur in a constructor call. (TODO: can we lift the ctor arg expression to a method and avoid statically synthesizing anonymous subclass altogether?) Typers: - no longer synthesize SAMs -- *adapt* a Function literal to the expected (SAM/FunctionN) type - Deal with polymorphic/existential sams (relevant tests: pos/t8310, pos/t5099.scala, pos/t4869.scala) We know where to find the result type, as all Function nodes have a FunctionN-shaped type during erasure. (Including function literals targeting a SAM type -- the sam type is tracked as the *expected* type.) Lift restriction on sam types being class types. It's enough that they dealias to one, like regular instance creation expressions. Contexts: - No longer need encl method hack for return in sam. Erasure: - erasure preserves SAM type for function nodes - Normalize sam to erased function type during erasure, otherwise we may box the function body from `$anonfun(args)` to `{$anonfun(args); ()}` because the expected type for the body is now `Object`, and thus `Unit` does not conform. Delambdafy: - must set static flag before calling createBoxingBridgeMethod - Refactored `createBoxingBridgeMethod` to wrap my head around boxing, reworked it to generalize from FunctionN's boxing needs to arbitrary LMF targets. Other refactorings: ThisReferringMethodsTraverser, TreeGen. --- test/files/neg/sammy_restrictions.check | 5 +---- test/files/neg/sammy_restrictions.scala | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'test/files/neg') diff --git a/test/files/neg/sammy_restrictions.check b/test/files/neg/sammy_restrictions.check index 8cc49f9aa9..0276f3a067 100644 --- a/test/files/neg/sammy_restrictions.check +++ b/test/files/neg/sammy_restrictions.check @@ -8,9 +8,6 @@ sammy_restrictions.scala:32: error: type mismatch; required: TwoAbstract ((x: Int) => 0): TwoAbstract ^ -sammy_restrictions.scala:34: error: class type required but DerivedOneAbstract with OneAbstract found - ((x: Int) => 0): NonClassType // "class type required". I think we should avoid SAM translation here. - ^ sammy_restrictions.scala:35: error: type mismatch; found : Int => Int required: NoEmptyConstructor @@ -46,4 +43,4 @@ sammy_restrictions.scala:44: error: type mismatch; required: PolyMethod ((x: Int) => 0): PolyMethod ^ -10 errors found +9 errors found diff --git a/test/files/neg/sammy_restrictions.scala b/test/files/neg/sammy_restrictions.scala index d003cfaf36..101342ad0b 100644 --- a/test/files/neg/sammy_restrictions.scala +++ b/test/files/neg/sammy_restrictions.scala @@ -31,7 +31,7 @@ object Test { (() => 0) : NoAbstract ((x: Int) => 0): TwoAbstract ((x: Int) => 0): DerivedOneAbstract // okay - ((x: Int) => 0): NonClassType // "class type required". I think we should avoid SAM translation here. + ((x: Int) => 0): NonClassType // okay -- we also allow type aliases in instantiation expressions, if they resolve to a class type ((x: Int) => 0): NoEmptyConstructor ((x: Int) => 0): OneEmptyConstructor // okay ((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call. -- cgit v1.2.3