diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-04-28 22:43:46 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan@lightbend.com> | 2016-08-11 10:59:14 -0700 |
commit | a97297d7d253eb7573c995ce936f364b56d9bfe9 (patch) | |
tree | 0c6b7d297dfe2e6c18ecbeb679eea6696a2362bb /test/files/run | |
parent | aab103eb999e2816c87c5010e7f7c79ed993fb90 (diff) | |
download | scala-a97297d7d253eb7573c995ce936f364b56d9bfe9.tar.gz scala-a97297d7d253eb7573c995ce936f364b56d9bfe9.tar.bz2 scala-a97297d7d253eb7573c995ce936f364b56d9bfe9.zip |
Fields phase
One step towards teasing apart the mixin phase, making
each phase that adds members to traits responsible for
mixing in those members into subclasses of said traits.
Another design tenet is to not emit symbols or trees
only to later remove them. Therefore, we model a
val in a trait as its accessor. The underlying field
is an implementation detail. It must be mixed into
subclasses, but has no business in a trait (an interface).
Also trying to reduce tree creation by changing less in subtrees
during tree transforms.
A lot of nice fixes fall out from this rework:
- Correct bridges and more precise generic signatures for
mixed in accessors, since they are now created before erasure.
- Correct enclosing method attribute for classes nested in trait fields.
Trait fields are now created as MethodSymbol (no longer TermSymbol).
This symbol shows up in the `originalOwner` chain of a class declared
within the field initializer. This promoted the field getter to
being the enclosing method of the nested class, which it is not
(the EnclosingMethod attribute is a source-level property).
- Signature inference is now more similar between vals and defs
- No more field for constant-typed vals, or mixed in accessors
for subclasses. A constant val can be fully implemented in a trait.
TODO:
- give same treatment to trait lazy vals (only accessors, no fields)
- remove support for presuper vals in traits
(they don't have the right init semantics in traits anyway)
- lambdalift should emit accessors for captured vals in traits,
not a field
Assorted notes from the full git history before squashing below.
Unit-typed vals: don't suppress field
it affects the memory model -- even a write of unit to a field is relevant...
unit-typed lazy vals should never receive a field
this need was unmasked by test/files/run/t7843-jsr223-service.scala,
which no longer printed the output expected from the `0 to 10 foreach`
Use getter.referenced to track traitsetter
reify's toolbox compiler changes the name of the trait
that owns the accessor between fields and constructors (`$` suffix),
so that the trait setter cannot be found when doing mkAssign in constructors
this could be solved by creating the mkAssign tree immediately during fields
anyway, first experiment: use `referenced` now that fields runs closer
to the constructors phase (I tried this before and something broke)
Infer result type for `val`s, like we do for `def`s
The lack of result type inference caused pos/t6780 to fail
in the new field encoding for traits, as there is no separate accessor,
and method synthesis computes the type signature based on the ValDef tree.
This caused a cyclic error in implicit search, because now the
implicit val's result type was not inferred from the super member,
and inferring it from the RHS would cause implicit search to consider
the member in question, so that a cycle is detected and type checking fails...
Regardless of the new encoding, we should consistently infer result types
for `def`s and `val`s.
Removed test/files/run/t4287inferredMethodTypes.scala and test/files/presentation/t4287c,
since they were relying on inferring argument types from "overridden" constructors
in a test for range positions of default arguments. Constructors don't override,
so that was a mis-feature of -Yinfer-argument-types.
Had to slightly refactor test/files/presentation/doc, as it was relying
on scalac inferring a big intersection type to approximate the anonymous
class that's instantiated for `override lazy val analyzer`.
Now that we infer `Global` as the expected type based on the overridden val,
we make `getComment` private in navigating between good old Skylla and Charybdis.
I'm not sure why we need this restriction for anonymous classes though;
only structural calls are restricted in the way that we're trying to avoid.
The old behavior is maintained nder -Xsource:2.11.
Tests:
- test/files/{pos,neg}/val_infer.scala
- test/files/neg/val_sig_infer_match.scala
- test/files/neg/val_sig_infer_struct.scala
need NMT when inferring sig for accessor
Q: why are we calling valDefSig and not methodSig?
A: traits use defs for vals, but still use valDefSig...
keep accessor and field info in synch
Diffstat (limited to 'test/files/run')
23 files changed, 278 insertions, 162 deletions
diff --git a/test/files/run/SymbolsTest.scala b/test/files/run/SymbolsTest.scala index d5948ea168..7c185b0e09 100644 --- a/test/files/run/SymbolsTest.scala +++ b/test/files/run/SymbolsTest.scala @@ -137,16 +137,16 @@ object Test { // } // val an2 = () => { // object nested { - // val m = 'mfsa + // val m = 'mfsa // } // nested.m // } // val an3 = () => { // object nested { - // val f = () => { - // 'layered - // } - // def gets = f() + // val f = () => { + // 'layered + // } + // def gets = f() // } // nested.gets // } @@ -204,8 +204,8 @@ object Test { val s1 = 's1 def s2 = 's2 object inner { - val s3 = 's3 - val s4 = 's4 + val s3 = 's3 + val s4 = 's4 } } @@ -223,8 +223,8 @@ object Test { val s5 = 's5 def s6 = 's6 object inner2 { - val s7 = 's7 - def s8 = 's8 + val s7 = 's7 + def s8 = 's8 } } assert(Local.s5 == 's5) diff --git a/test/files/run/analyzerPlugins.check b/test/files/run/analyzerPlugins.check index 1bb7c6ceab..ca0005ea4d 100644 --- a/test/files/run/analyzerPlugins.check +++ b/test/files/run/analyzerPlugins.check @@ -21,7 +21,6 @@ lub(List(Int @testAnn, Int)) [1] pluginsPt(?, Trees$Annotated) [7] pluginsPt(?, Trees$Apply) [11] pluginsPt(?, Trees$ApplyImplicitView) [2] -pluginsPt(?, Trees$Assign) [7] pluginsPt(?, Trees$Block) [4] pluginsPt(?, Trees$ClassDef) [2] pluginsPt(?, Trees$DefDef) [14] @@ -31,9 +30,9 @@ pluginsPt(?, Trees$Literal) [16] pluginsPt(?, Trees$New) [5] pluginsPt(?, Trees$PackageDef) [1] pluginsPt(?, Trees$Return) [1] -pluginsPt(?, Trees$Select) [50] +pluginsPt(?, Trees$Select) [43] pluginsPt(?, Trees$Super) [2] -pluginsPt(?, Trees$This) [20] +pluginsPt(?, Trees$This) [13] pluginsPt(?, Trees$TypeApply) [3] pluginsPt(?, Trees$TypeBoundsTree) [2] pluginsPt(?, Trees$TypeDef) [1] @@ -47,23 +46,19 @@ pluginsPt(Boolean @testAnn, Trees$Literal) [1] pluginsPt(Boolean @testAnn, Trees$Select) [1] pluginsPt(Boolean, Trees$Apply) [1] pluginsPt(Boolean, Trees$Ident) [1] -pluginsPt(Boolean, Trees$Literal) [1] pluginsPt(Double, Trees$Select) [1] pluginsPt(Int @testAnn, Trees$Literal) [1] pluginsPt(Int, Trees$Apply) [1] -pluginsPt(Int, Trees$Ident) [2] -pluginsPt(Int, Trees$If) [1] -pluginsPt(Int, Trees$Literal) [5] +pluginsPt(Int, Trees$Ident) [1] +pluginsPt(Int, Trees$Literal) [4] pluginsPt(Int, Trees$Select) [3] -pluginsPt(List, Trees$Apply) [1] pluginsPt(List[Any], Trees$Select) [1] pluginsPt(String @testAnn, Trees$Select) [1] pluginsPt(String, Trees$Apply) [1] pluginsPt(String, Trees$Block) [2] -pluginsPt(String, Trees$Ident) [4] +pluginsPt(String, Trees$Ident) [3] pluginsPt(String, Trees$Literal) [1] pluginsPt(String, Trees$Select) [1] -pluginsPt(String, Trees$Typed) [1] pluginsPt(Unit, Trees$Assign) [1] pluginsPt(testAnn, Trees$Apply) [5] pluginsTypeSig(<none>, Trees$Template) [2] @@ -119,7 +114,7 @@ pluginsTyped(=> Int, Trees$TypeApply) [1] pluginsTyped(=> String @testAnn, Trees$Select) [1] pluginsTyped(A, Trees$Apply) [1] pluginsTyped(A, Trees$Ident) [2] -pluginsTyped(A, Trees$This) [8] +pluginsTyped(A, Trees$This) [1] pluginsTyped(A, Trees$TypeTree) [4] pluginsTyped(A.super.type, Trees$Super) [1] pluginsTyped(A.this.type, Trees$This) [11] @@ -128,25 +123,23 @@ pluginsTyped(AnyRef, Trees$Select) [4] pluginsTyped(Array[Any], Trees$ArrayValue) [1] pluginsTyped(Boolean @testAnn, Trees$Select) [1] pluginsTyped(Boolean @testAnn, Trees$TypeTree) [4] -pluginsTyped(Boolean(false), Trees$Literal) [2] +pluginsTyped(Boolean(false), Trees$Literal) [1] pluginsTyped(Boolean, Trees$Apply) [1] -pluginsTyped(Boolean, Trees$Select) [4] +pluginsTyped(Boolean, Trees$Select) [3] pluginsTyped(Char('c'), Trees$Literal) [2] pluginsTyped(Double, Trees$Apply) [3] pluginsTyped(Double, Trees$Select) [6] pluginsTyped(Int @testAnn, Trees$TypeTree) [2] pluginsTyped(Int @testAnn, Trees$Typed) [2] -pluginsTyped(Int(0), Trees$Literal) [3] +pluginsTyped(Int(0), Trees$Literal) [2] pluginsTyped(Int(1) @testAnn, Trees$Typed) [1] pluginsTyped(Int(1), Trees$Literal) [8] pluginsTyped(Int(2), Trees$Literal) [1] pluginsTyped(Int, Trees$Apply) [1] -pluginsTyped(Int, Trees$Ident) [2] -pluginsTyped(Int, Trees$If) [2] -pluginsTyped(Int, Trees$Select) [15] +pluginsTyped(Int, Trees$Ident) [1] +pluginsTyped(Int, Trees$If) [1] +pluginsTyped(Int, Trees$Select) [12] pluginsTyped(Int, Trees$TypeTree) [13] -pluginsTyped(List, Trees$Apply) [1] -pluginsTyped(List, Trees$Select) [1] pluginsTyped(List[Any], Trees$Apply) [1] pluginsTyped(List[Any], Trees$Select) [1] pluginsTyped(List[Any], Trees$TypeTree) [3] @@ -159,15 +152,13 @@ pluginsTyped(String(""), Trees$Literal) [2] pluginsTyped(String("huhu"), Trees$Literal) [1] pluginsTyped(String("str") @testAnn, Trees$Typed) [1] pluginsTyped(String("str"), Trees$Literal) [1] -pluginsTyped(String("str"), Trees$Typed) [1] pluginsTyped(String("two"), Trees$Literal) [2] pluginsTyped(String, Trees$Apply) [2] pluginsTyped(String, Trees$Block) [2] -pluginsTyped(String, Trees$Ident) [1] -pluginsTyped(String, Trees$Select) [9] +pluginsTyped(String, Trees$Select) [7] pluginsTyped(String, Trees$TypeTree) [7] pluginsTyped(Unit, Trees$Apply) [2] -pluginsTyped(Unit, Trees$Assign) [8] +pluginsTyped(Unit, Trees$Assign) [1] pluginsTyped(Unit, Trees$Block) [4] pluginsTyped(Unit, Trees$If) [1] pluginsTyped(Unit, Trees$Literal) [5] diff --git a/test/files/run/programmatic-main.check b/test/files/run/programmatic-main.check index 280a4f43d5..03f8273c17 100644 --- a/test/files/run/programmatic-main.check +++ b/test/files/run/programmatic-main.check @@ -10,17 +10,18 @@ superaccessors 6 add super accessors in traits and nested classes pickler 8 serialize symbol tables refchecks 9 reference/override checking, translate nested objects uncurry 10 uncurry, translate function values to anonymous classes - tailcalls 11 replace tail calls by jumps - specialize 12 @specialized-driven class and method specialization - explicitouter 13 this refs to outer pointers - erasure 14 erase types, add interfaces for traits - posterasure 15 clean up erased inline classes - lazyvals 16 allocate bitmaps, translate lazy vals into lazified defs - lambdalift 17 move nested functions to top level - constructors 18 move field definitions into constructors - flatten 19 eliminate inner classes - mixin 20 mixin composition - cleanup 21 platform-specific cleanups, generate reflective calls - delambdafy 22 remove lambdas - jvm 23 generate JVM bytecode - terminal 24 the last phase during a compilation run + fields 11 synthesize accessors and fields + tailcalls 12 replace tail calls by jumps + specialize 13 @specialized-driven class and method specialization + explicitouter 14 this refs to outer pointers + erasure 15 erase types, add interfaces for traits + posterasure 16 clean up erased inline classes + lazyvals 17 allocate bitmaps, translate lazy vals into lazified defs + lambdalift 18 move nested functions to top level + constructors 19 move field definitions into constructors + flatten 20 eliminate inner classes + mixin 21 mixin composition + cleanup 22 platform-specific cleanups, generate reflective calls + delambdafy 23 remove lambdas + jvm 24 generate JVM bytecode + terminal 25 the last phase during a compilation run diff --git a/test/files/run/reflection-fieldsymbol-navigation.check b/test/files/run/reflection-fieldsymbol-navigation.check index ae0597a045..fd06c78a18 100644 --- a/test/files/run/reflection-fieldsymbol-navigation.check +++ b/test/files/run/reflection-fieldsymbol-navigation.check @@ -1,6 +1,6 @@ -method x +variable x false variable x true -method x -method x_= +variable x +variable x diff --git a/test/files/run/repl-colon-type.check b/test/files/run/repl-colon-type.check index 21fbe34d96..1217e8d8c2 100644 --- a/test/files/run/repl-colon-type.check +++ b/test/files/run/repl-colon-type.check @@ -35,7 +35,7 @@ Int scala> :type protected lazy val f = 5 <console>:5: error: lazy value f cannot be accessed in object $iw - Access to protected value f not permitted because + Access to protected lazy value f not permitted because enclosing object $eval in package $line13 is not a subclass of object $iw where target is defined lazy val $result = f diff --git a/test/files/run/showdecl.check b/test/files/run/showdecl.check index b8d7f94c57..d431c36f6d 100644 --- a/test/files/run/showdecl.check +++ b/test/files/run/showdecl.check @@ -8,7 +8,7 @@ initialized y: lazy val y: Int uninitialized z: def z: <?> initialized z: def z: Int uninitialized t: def t: <?> -initialized t: def t[T <: Int](x: D)(y: x.W): Int +initialized t: def t[T <: <?>](x: D)(y: x.W): Int uninitialized W: type W = String initialized W: type W = String uninitialized C: class C extends diff --git a/test/files/run/showdecl/Macros_1.scala b/test/files/run/showdecl/Macros_1.scala index c68dd275de..89b8e8d3c2 100644 --- a/test/files/run/showdecl/Macros_1.scala +++ b/test/files/run/showdecl/Macros_1.scala @@ -9,7 +9,7 @@ object Macros { import c.universe._ def test(sym: Symbol): Unit = { println(s"uninitialized ${sym.name}: ${showDecl(sym)}") - sym.info + sym.info // NOTE: not fullyInitializeSymbol, so some parts may still be LazyTypes println(s"initialized ${sym.name}: ${showDecl(sym)}") } diff --git a/test/files/run/showraw_mods.check b/test/files/run/showraw_mods.check index 4d34160422..ff77d22adf 100644 --- a/test/files/run/showraw_mods.check +++ b/test/files/run/showraw_mods.check @@ -1 +1 @@ -Block(List(ClassDef(Modifiers(ABSTRACT | DEFAULTPARAM/TRAIT), TypeName("C"), List(), Template(List(Ident(TypeName("AnyRef"))), noSelfType, List(DefDef(Modifiers(), TermName("$init$"), List(), List(List()), TypeTree(), Block(List(), Literal(Constant(())))), ValDef(Modifiers(PRIVATE | LOCAL), TermName("x"), TypeTree(), Literal(Constant(2))), ValDef(Modifiers(MUTABLE), TermName("y"), TypeTree(), Select(This(TypeName("C")), TermName("x"))), ValDef(Modifiers(LAZY), TermName("z"), TypeTree(), Select(This(TypeName("C")), TermName("y"))))))), Literal(Constant(()))) +Block(List(ClassDef(Modifiers(ABSTRACT | DEFAULTPARAM/TRAIT), TypeName("C"), List(), Template(List(Ident(TypeName("AnyRef"))), noSelfType, List(DefDef(Modifiers(), TermName("$init$"), List(), List(List()), TypeTree(), Block(List(), Literal(Constant(())))), DefDef(Modifiers(PRIVATE | METHOD | LOCAL | STABLE | ACCESSOR), TermName("x"), List(), List(), TypeTree(), Literal(Constant(2))), DefDef(Modifiers(METHOD | ACCESSOR), TermName("y"), List(), List(), TypeTree(), Select(This(TypeName("C")), TermName("x"))), DefDef(Modifiers(METHOD | ACCESSOR), TermName("y_$eq"), List(), List(List(ValDef(Modifiers(PARAM | SYNTHETIC), TermName("x$1"), TypeTree(), EmptyTree))), TypeTree(), EmptyTree), ValDef(Modifiers(LAZY), TermName("z"), TypeTree(), Select(This(TypeName("C")), TermName("y"))))))), Literal(Constant(()))) diff --git a/test/files/run/t4287inferredMethodTypes.check b/test/files/run/t4287inferredMethodTypes.check deleted file mode 100644 index 56e9c097cc..0000000000 --- a/test/files/run/t4287inferredMethodTypes.check +++ /dev/null @@ -1,30 +0,0 @@ -[[syntax trees at end of typer]] // newSource1.scala -[0:92]package [0:0]<empty> { - [0:21]class A extends [7:21][23]scala.AnyRef { - [8:16]<paramaccessor> private[this] val a: [8]Int = _; - <8:20>def <init>(<8:20>a: [11]<type: [11]scala.Int> = [17:20]A.a): [7]A = <8:20>{ - <8:20><8:20><8:20>A.super.<init>(); - <8:20>() - } - }; - [23:47]object A extends [32:47][49]scala.AnyRef { - [49]def <init>(): [32]A.type = [49]{ - [49][49][49]A.super.<init>(); - [32]() - }; - [36:45]private[this] val a: [40]Int = [44:45]2; - [40]<stable> <accessor> def a: [40]Int = [40][40]A.this.a; - [8]<synthetic> def <init>$default$1: [8]Int = [19]A.a - }; - [49:92]class B extends [57:92][65:66]A { - [65]def <init>(): [57]B = [65]{ - [65][65][65]B.super.<init>([65]A.<init>$default$1); - [57]() - }; - [70:90]def <init>([79:80]a: [79]Int): [74]B = [84:90]{ - [84:90][84:90][84]B.this.<init>(); - [84]() - } - } -} - diff --git a/test/files/run/t4287inferredMethodTypes.scala b/test/files/run/t4287inferredMethodTypes.scala deleted file mode 100644 index f14e672da8..0000000000 --- a/test/files/run/t4287inferredMethodTypes.scala +++ /dev/null @@ -1,25 +0,0 @@ -import scala.tools.partest.DirectTest - -object Test extends DirectTest { - - override def extraSettings: String = - s"-usejavacp -Yinfer-argument-types -Xprint-pos -Xprint:typer -Yrangepos -Ystop-after:typer -d ${testOutput.path}" - - override def code = """ -class A(a: Int = A.a) - -object A { - val a = 2 -} - -class B extends A { - def this(a) = this() -} - """.trim - - override def show(): Unit = { - Console.withErr(System.out) { - compile() - } - } -}
\ No newline at end of file diff --git a/test/files/run/t6733.check b/test/files/run/t6733.check index aeb595fbfd..7062301c56 100644 --- a/test/files/run/t6733.check +++ b/test/files/run/t6733.check @@ -2,23 +2,22 @@ method $init$: isPrivateThis = false, isProtectedThis = false value pri1a: isPrivateThis = true, isProtectedThis = false method pri2a: isPrivateThis = true, isProtectedThis = false variable pri3a: isPrivateThis = true, isProtectedThis = false -value pri4a: isPrivateThis = true, isProtectedThis = false +variable pri3a: isPrivateThis = true, isProtectedThis = false +lazy value pri4a: isPrivateThis = true, isProtectedThis = false lazy value pri4a: isPrivateThis = true, isProtectedThis = false type Pri5a: isPrivateThis = true, isProtectedThis = false class Pri6: isPrivateThis = true, isProtectedThis = false trait Pri7: isPrivateThis = true, isProtectedThis = false object Pri8: isPrivateThis = true, isProtectedThis = false value pro1a: isPrivateThis = false, isProtectedThis = true -value pro1a: isPrivateThis = true, isProtectedThis = false value pro1b: isPrivateThis = false, isProtectedThis = true method pro2a: isPrivateThis = false, isProtectedThis = true method pro2b: isPrivateThis = false, isProtectedThis = true -method pro3a: isPrivateThis = false, isProtectedThis = true -method pro3a_=: isPrivateThis = false, isProtectedThis = true -variable pro3a: isPrivateThis = true, isProtectedThis = false -method pro3b: isPrivateThis = false, isProtectedThis = true -method pro3b_=: isPrivateThis = false, isProtectedThis = true -value pro4a: isPrivateThis = false, isProtectedThis = true +variable pro3a: isPrivateThis = false, isProtectedThis = true +variable pro3a: isPrivateThis = false, isProtectedThis = true +variable pro3b: isPrivateThis = false, isProtectedThis = true +variable pro3b: isPrivateThis = false, isProtectedThis = true +lazy value pro4a: isPrivateThis = false, isProtectedThis = true lazy value pro4a: isPrivateThis = true, isProtectedThis = false type Pro5a: isPrivateThis = false, isProtectedThis = true type Pro5b: isPrivateThis = false, isProtectedThis = true diff --git a/test/files/run/t7533.check b/test/files/run/t7533.check index fa5b3edc8f..61fd4657bd 100644 --- a/test/files/run/t7533.check +++ b/test/files/run/t7533.check @@ -1,30 +1,29 @@ Testing Symbol.isAbstract... =======class C======= -class C => true -constructor C => false -value x1 => true -value x2 => false -value x2 => false -method y1 => true -method y2 => false -type T1 => true -type T2 => false +class C => abstract +constructor C => concrete +value xAbs => abstract +value x => concrete +value x => concrete +method yAbs => abstract +method y => concrete +type TAbs => abstract +type T => concrete =======trait T======= -trait T => true -method $init$ => false -value z1 => true -value z2 => false -value z2 => false -method w1 => true -method w2 => false -type U1 => true -type U2 => false -=======class D======= -class D => false -constructor D => false -value x1 => false -value x1 => false -method y1 => false +trait T => abstract +method $init$ => concrete +value zAbs => abstract +value z => concrete +method wAbs => abstract +method w => concrete +type UAbs => abstract +type U => concrete +=======class AllConcrete======= +class AllConcrete => concrete +constructor AllConcrete => concrete +value xAbs => concrete +value xAbs => concrete +method yAbs => concrete =======object M======= -object M => false -constructor M => false +object M => concrete +constructor M => concrete diff --git a/test/files/run/t7533.scala b/test/files/run/t7533.scala index c7bd8e8d43..65c5c26b42 100644 --- a/test/files/run/t7533.scala +++ b/test/files/run/t7533.scala @@ -1,24 +1,24 @@ import scala.reflect.runtime.universe._ abstract class C { - val x1: Int - val x2: Int = 2 - def y1: Int - def y2: Int = 2 - type T1 <: Int - type T2 = Int + val xAbs: Int + val x: Int = 2 + def yAbs: Int + def y: Int = 2 + type TAbs <: Int + type T = Int } trait T { - val z1: Int - val z2: Int = 2 - def w1: Int - def w2: Int = 2 - type U1 <: Int - type U2 = Int + val zAbs: Int + val z: Int = 2 + def wAbs: Int + def w: Int = 2 + type UAbs <: Int + type U = Int } -class D extends C { - val x1 = 3 - def y1 = 3 +class AllConcrete extends C { + val xAbs = 3 + def yAbs = 3 } object M @@ -27,12 +27,12 @@ object Test extends App { def test[T: TypeTag] = { val sym = typeOf[T].typeSymbol println(s"=======$sym=======") - def printAbstract(sym: Symbol) = println(s"$sym => ${sym.isAbstract}") + def printAbstract(sym: Symbol) = println(s"$sym => ${if (sym.isAbstract) "abstract" else "concrete"}") printAbstract(sym) sym.info.decls.sorted.foreach(printAbstract) } test[C] test[T] - test[D] + test[AllConcrete] test[M.type] }
\ No newline at end of file diff --git a/test/files/run/t8549.scala b/test/files/run/t8549.scala index da7a731459..7a38491231 100644 --- a/test/files/run/t8549.scala +++ b/test/files/run/t8549.scala @@ -79,7 +79,7 @@ object Test extends App { } } - // Generated on 20160715-08:27:53 with Scala version 2.12.0-20160715-012500-f5a80bd) + // Generated on 20160720-18:56:11 with Scala version 2.12.0-local-5815f9a) overwrite.foreach(updateComment) check(Some(1))("rO0ABXNyAApzY2FsYS5Tb21lESLyaV6hi3QCAAFMAAV2YWx1ZXQAEkxqYXZhL2xhbmcvT2JqZWN0O3hyAAxzY2FsYS5PcHRpb27+aTf92w5mdAIAAHhwc3IAEWphdmEubGFuZy5JbnRlZ2VyEuKgpPeBhzgCAAFJAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAAE=") @@ -174,7 +174,7 @@ object Test extends App { // check(mutable.ArraySeq(1, 2, 3))( "rO0ABXNyACFzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuQXJyYXlTZXEVPD3SKEkOcwIAAkkABmxlbmd0aFsABWFycmF5dAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwAAAAA3VyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAANzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAXNxAH4ABQAAAAJzcQB+AAUAAAAD") check(mutable.AnyRefMap("a" -> "A"))( "rO0ABXNyACJzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuQW55UmVmTWFwAAAAAAAAAAECAAdJAAVfc2l6ZUkAB192YWNhbnRJAARtYXNrTAAMZGVmYXVsdEVudHJ5dAARTHNjYWxhL0Z1bmN0aW9uMTtbACtzY2FsYSRjb2xsZWN0aW9uJG11dGFibGUkQW55UmVmTWFwJCRfaGFzaGVzdAACW0lbAClzY2FsYSRjb2xsZWN0aW9uJG11dGFibGUkQW55UmVmTWFwJCRfa2V5c3QAE1tMamF2YS9sYW5nL09iamVjdDtbACtzY2FsYSRjb2xsZWN0aW9uJG11dGFibGUkQW55UmVmTWFwJCRfdmFsdWVzcQB+AAN4cAAAAAEAAAAAAAAAB3NyADNzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuQW55UmVmTWFwJEV4Y2VwdGlvbkRlZmF1bHQAAAAAAAAAAQIAAHhwdXIAAltJTbpgJnbqsqUCAAB4cAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+UkA2AAAAAHVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAAhwcHBwcHB0AAFhcHVxAH4ACQAAAAhwcHBwcHB0AAFBcA==") check(mutable.ArrayStack(1, 2, 3))( "rO0ABXNyACNzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuQXJyYXlTdGFja3bdxXbcnLBeAgACSQAqc2NhbGEkY29sbGVjdGlvbiRtdXRhYmxlJEFycmF5U3RhY2skJGluZGV4WwAqc2NhbGEkY29sbGVjdGlvbiRtdXRhYmxlJEFycmF5U3RhY2skJHRhYmxldAATW0xqYXZhL2xhbmcvT2JqZWN0O3hwAAAAA3VyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAANzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAA3NxAH4ABQAAAAJzcQB+AAUAAAAB") - check(mutable.DoubleLinkedList(1, 2, 3))( "rO0ABXNyAClzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuRG91YmxlTGlua2VkTGlzdI73LKsKRr1RAgADTAAEZWxlbXQAEkxqYXZhL2xhbmcvT2JqZWN0O0wABG5leHR0AB5Mc2NhbGEvY29sbGVjdGlvbi9tdXRhYmxlL1NlcTtMAARwcmV2cQB+AAJ4cHNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAABc3EAfgAAc3EAfgAEAAAAAnNxAH4AAHNxAH4ABAAAAANzcQB+AABwcQB+AAtxAH4ACXEAfgAHcQB+AANw") + check(mutable.DoubleLinkedList(1, 2, 3))( "rO0ABXNyAClzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuRG91YmxlTGlua2VkTGlzdI73LKsKRr1RAgADTAAEZWxlbXQAEkxqYXZhL2xhbmcvT2JqZWN0O0wABG5leHR0ACtMc2NhbGEvY29sbGVjdGlvbi9tdXRhYmxlL0RvdWJsZUxpbmtlZExpc3Q7TAAEcHJldnEAfgACeHBzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAXNxAH4AAHNxAH4ABAAAAAJzcQB+AABzcQB+AAQAAAADc3EAfgAAcHEAfgALcQB+AAlxAH4AB3EAfgADcA==") check(mutable.HashMap())( "rO0ABXNyACBzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuSGFzaE1hcAAAAAAAAAABAwAAeHB3DQAAAu4AAAAAAAAABAB4") check(mutable.HashMap(1 -> 1))( "rO0ABXNyACBzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuSGFzaE1hcAAAAAAAAAABAwAAeHB3DQAAAu4AAAABAAAABABzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAXEAfgAEeA==") @@ -189,7 +189,7 @@ object Test extends App { // check(new mutable.History())( "rO0ABXNyACBzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuSGlzdG9yeUhuXxDIFJrsAgACSQAKbWF4SGlzdG9yeUwAA2xvZ3QAIExzY2FsYS9jb2xsZWN0aW9uL211dGFibGUvUXVldWU7eHAAAAPoc3IAHnNjYWxhLmNvbGxlY3Rpb24ubXV0YWJsZS5RdWV1ZbjMURVfOuHHAgAAeHIAJHNjYWxhLmNvbGxlY3Rpb24ubXV0YWJsZS5NdXRhYmxlTGlzdFJpnjJ+gFbAAgADSQADbGVuTAAGZmlyc3QwdAAlTHNjYWxhL2NvbGxlY3Rpb24vbXV0YWJsZS9MaW5rZWRMaXN0O0wABWxhc3QwcQB+AAV4cAAAAABzcgAjc2NhbGEuY29sbGVjdGlvbi5tdXRhYmxlLkxpbmtlZExpc3Sak+nGCZHaUQIAAkwABGVsZW10ABJMamF2YS9sYW5nL09iamVjdDtMAARuZXh0dAAeTHNjYWxhL2NvbGxlY3Rpb24vbXV0YWJsZS9TZXE7eHBwcQB+AApxAH4ACg==") check(mutable.LinkedHashMap(1 -> 2))( "rO0ABXNyACZzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuTGlua2VkSGFzaE1hcAAAAAAAAAABAwAAeHB3DQAAAu4AAAABAAAABABzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAXNxAH4AAgAAAAJ4") check(mutable.LinkedHashSet(1, 2, 3))( "rO0ABXNyACZzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuTGlua2VkSGFzaFNldAAAAAAAAAABAwAAeHB3DQAAAu4AAAADAAAABABzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAXNxAH4AAgAAAAJzcQB+AAIAAAADeA==") - check(mutable.LinkedList(1, 2, 3))( "rO0ABXNyACNzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuTGlua2VkTGlzdJqT6cYJkdpRAgACTAAEZWxlbXQAEkxqYXZhL2xhbmcvT2JqZWN0O0wABG5leHR0AB5Mc2NhbGEvY29sbGVjdGlvbi9tdXRhYmxlL1NlcTt4cHNyABFqYXZhLmxhbmcuSW50ZWdlchLioKT3gYc4AgABSQAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAABc3EAfgAAc3EAfgAEAAAAAnNxAH4AAHNxAH4ABAAAAANzcQB+AABwcQB+AAs=") + check(mutable.LinkedList(1, 2, 3))( "rO0ABXNyACNzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuTGlua2VkTGlzdJqT6cYJkdpRAgACTAAEZWxlbXQAEkxqYXZhL2xhbmcvT2JqZWN0O0wABG5leHR0ACVMc2NhbGEvY29sbGVjdGlvbi9tdXRhYmxlL0xpbmtlZExpc3Q7eHBzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAXNxAH4AAHNxAH4ABAAAAAJzcQB+AABzcQB+AAQAAAADc3EAfgAAcHEAfgAL") // TODO SI-8576 unstable under -Xcheckinit // check(mutable.ListBuffer(1, 2, 3))( "rO0ABXNyACNzY2FsYS5jb2xsZWN0aW9uLm11dGFibGUuTGlzdEJ1ZmZlci9y9I7QyWzGAwAEWgAIZXhwb3J0ZWRJAANsZW5MAAVsYXN0MHQAKUxzY2FsYS9jb2xsZWN0aW9uL2ltbXV0YWJsZS8kY29sb24kY29sb247TAAqc2NhbGEkY29sbGVjdGlvbiRtdXRhYmxlJExpc3RCdWZmZXIkJHN0YXJ0dAAhTHNjYWxhL2NvbGxlY3Rpb24vaW1tdXRhYmxlL0xpc3Q7eHBzcgARamF2YS5sYW5nLkludGVnZXIS4qCk94GHOAIAAUkABXZhbHVleHIAEGphdmEubGFuZy5OdW1iZXKGrJUdC5TgiwIAAHhwAAAAAXNxAH4ABAAAAAJzcQB+AAQAAAADc3IALHNjYWxhLmNvbGxlY3Rpb24uaW1tdXRhYmxlLkxpc3RTZXJpYWxpemVFbmQkilxjW/dTC20CAAB4cHcFAAAAAAN4") diff --git a/test/files/run/trait_fields_bytecode.scala b/test/files/run/trait_fields_bytecode.scala new file mode 100644 index 0000000000..d87412f43e --- /dev/null +++ b/test/files/run/trait_fields_bytecode.scala @@ -0,0 +1,23 @@ +trait TFinal { final val bla: Int = 123 } + +// bla should be final in C +class CFinal extends TFinal + + +trait TConst { final val C = "S" } +// there should be a C method in `T$class`! +class CConst extends TConst { } + + +object Test { + def main(args: Array[String]): Unit = { + val f1 = classOf[CFinal].getDeclaredMethod("bla") + import java.lang.reflect.Modifier._ + assert(isFinal(f1.getModifiers), f1) + + classOf[CConst].getMethod("C") + + import language.reflectiveCalls + assert(new CConst().asInstanceOf[{def C: String}].C == "S") + } +} diff --git a/test/files/run/trait_fields_final.scala b/test/files/run/trait_fields_final.scala new file mode 100644 index 0000000000..8b32e5b47d --- /dev/null +++ b/test/files/run/trait_fields_final.scala @@ -0,0 +1,21 @@ +// TODO: clarify meaning of final in traits +// In the new compiler, there's no final modifier after mixin for `meh`'s setter, +// whereas 2.12.0-M3 makes meh's trait setter final. +// NOTE: bytecode is identical, but the scalasignature is different +trait Foo { self: Meh => + def bar(x: String) = x == "a" + private final val meh = bar("a") +} + +abstract class Meh extends Foo + +object Test { + def main(args: Array[String]): Unit = { + val setter = classOf[Meh].getDeclaredMethod("Foo$_setter_$Foo$$meh_$eq", java.lang.Boolean.TYPE) + val getter = classOf[Meh].getDeclaredMethod("Foo$$meh") + import java.lang.reflect.Modifier._ + assert(isFinal(setter.getModifiers), setter) + assert(isFinal(getter.getModifiers), getter) + } + +} diff --git a/test/files/run/trait_fields_init.check b/test/files/run/trait_fields_init.check new file mode 100644 index 0000000000..84c1a2ead9 --- /dev/null +++ b/test/files/run/trait_fields_init.check @@ -0,0 +1,21 @@ +x +y +z +abstract +public +protected +abstract protected +private +private[this] +abstract +public +protected +abstract protected +private +private[this] +abstract +public +protected +abstract protected +private +private[this] diff --git a/test/files/run/trait_fields_init.scala b/test/files/run/trait_fields_init.scala new file mode 100644 index 0000000000..496911d538 --- /dev/null +++ b/test/files/run/trait_fields_init.scala @@ -0,0 +1,55 @@ +trait T { + val abs: String + protected val protabs: String + val pub = "public" + protected val prot = "protected" + private val privvy = "private" + private[this] val privateThis = "private[this]" + // TODO: + // final val const = "const" + + trait Nested { println(abs + privateThis) } + + object NO { + println(abs) + println(pub) + println(prot) + println(protabs) + println(privvy) + println(privateThis) + } + + trait NT { + println(abs) + println(pub) + println(prot) + println(protabs) + println(privvy) + println(privateThis) + } + + class NC { + println(abs) + println(pub) + println(prot) + println(protabs) + println(privvy) + println(privateThis) + } +} + +class C extends AnyRef with T { + println("x") + val abs = "abstract" + println("y") + val protabs = "abstract protected" + final val const = "const" + println("z") +} + +object Test extends C { + def main(args: Array[String]): Unit = { + NO + new NT{} + new NC +}}
\ No newline at end of file diff --git a/test/files/run/trait_fields_repl.check b/test/files/run/trait_fields_repl.check new file mode 100644 index 0000000000..d03a565c7b --- /dev/null +++ b/test/files/run/trait_fields_repl.check @@ -0,0 +1,11 @@ + +scala> trait B { val y = "a" } +defined trait B + +scala> trait T extends B { val x: y.type = y } +defined trait T + +scala> println((new T{}).x) +a + +scala> :quit diff --git a/test/files/run/trait_fields_repl.scala b/test/files/run/trait_fields_repl.scala new file mode 100644 index 0000000000..311477b7d2 --- /dev/null +++ b/test/files/run/trait_fields_repl.scala @@ -0,0 +1,10 @@ +// TODO: fix AME when this runs in REPL +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ +trait B { val y = "a" } +trait T extends B { val x: y.type = y } +println((new T{}).x) +""" +} diff --git a/test/files/run/trait_fields_three_layer_overrides.check b/test/files/run/trait_fields_three_layer_overrides.check new file mode 100644 index 0000000000..8bb45803c5 --- /dev/null +++ b/test/files/run/trait_fields_three_layer_overrides.check @@ -0,0 +1,2 @@ +the real universe.TypeTag +1 diff --git a/test/files/run/trait_fields_three_layer_overrides.scala b/test/files/run/trait_fields_three_layer_overrides.scala new file mode 100644 index 0000000000..9d7aa94341 --- /dev/null +++ b/test/files/run/trait_fields_three_layer_overrides.scala @@ -0,0 +1,25 @@ +// interesting hierarchies/overrides distilled from reflect/compiler + +trait Aliases { + val TypeTag = "universe.TypeTag" +} +trait AliasesOverrides extends Aliases { // or self: Aliases => + override val TypeTag = "the real universe.TypeTag" +} +class Context extends Aliases with AliasesOverrides + + + +trait SymbolTable { + def currentRunId: Int = -1 +} +trait ReflectSetup extends SymbolTable { + override val currentRunId = 1 +} +class G extends SymbolTable with ReflectSetup + + +object Test extends App { + println((new Context).TypeTag) + println((new G).currentRunId) +}
\ No newline at end of file diff --git a/test/files/run/trait_fields_volatile.scala b/test/files/run/trait_fields_volatile.scala new file mode 100644 index 0000000000..eedb6de1c2 --- /dev/null +++ b/test/files/run/trait_fields_volatile.scala @@ -0,0 +1,13 @@ +// bytecode should reflect volatile annotation +trait VolatileAbort { + @volatile private var abortflag = false +} +class DefaultSignalling extends VolatileAbort + +object Test { + def main(args: Array[String]): Unit = { + val field = classOf[DefaultSignalling].getDeclaredFields.find(_.getName.contains("abortflag")).get + assert(java.lang.reflect.Modifier.isVolatile(field.getModifiers), field) + } + +} |