diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2016-07-14 16:52:20 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan@lightbend.com> | 2016-08-29 09:52:04 +0200 |
commit | df3689139c4d4bcd2933364d13b8195c3433eb43 (patch) | |
tree | 0e8a6cbf6a870869a4ffac6e1a90be2cbf9f1320 /test/files/run | |
parent | a3604707303e4b1f45b6afabccaf00510b281912 (diff) | |
download | scala-df3689139c4d4bcd2933364d13b8195c3433eb43.tar.gz scala-df3689139c4d4bcd2933364d13b8195c3433eb43.tar.bz2 scala-df3689139c4d4bcd2933364d13b8195c3433eb43.zip |
Fields phase expands lazy vals like modules
They remain ValDefs until then.
- remove lazy accessor logic
now that we have a single ValDef for lazy vals,
with the underlying machinery being hidden until the fields phase
leave a `@deprecated def lazyAccessor` for scala-refactoring
- don't skolemize in purely synthetic getters,
but *do* skolemize in lazy accessor during typers
Lazy accessors have arbitrary user code, so have to skolemize.
We exempt the purely synthetic accessors (`isSyntheticAccessor`)
for strict vals, and lazy accessors emitted by the fields phase
to avoid spurious type mismatches due to issues with existentials
(That bug is tracked as https://github.com/scala/scala-dev/issues/165)
When we're past typer, lazy accessors are synthetic,
but before they are user-defined to make this hack less hacky,
we could rework our flag usage to allow for
requiring both the ACCESSOR and the SYNTHETIC bits
to identify synthetic accessors and trigger the exemption.
see also https://github.com/scala/scala-dev/issues/165
ok 7 - pos/existentials-harmful.scala
ok 8 - pos/t2435.scala
ok 9 - pos/existentials.scala
previous attempt: skolemize type of val inside the private[this] val
because its type is only observed from inside the
accessor methods (inside the method scope its existentials are skolemized)
- bean accessors have regular method types, not nullary method types
- must re-infer type for param accessor
some weirdness with scoping of param accessor vals and defs?
- tailcalls detect lazy vals, which are defdefs after fields
- can inline constant lazy val from trait
- don't mix in fields etc for an overridden lazy val
- need try-lift in lazy vals: the assign is not seen in uncurry
because fields does the transform (see run/t2333.scala)
- ensure field members end up final in bytecode
- implicit class companion method: annot filter in completer
- update check: previous error message was tangled up with unrelated
field definitions (`var s` and `val s_scope`),
now it behaves consistently whether those are val/vars or defs
- analyzer plugin check update seems benign, but no way to know...
- error message gen: there is no underlying symbol for a deferred var
look for missing getter/setter instead
- avoid retypechecking valdefs while duplicating for specialize
see pos/spec-private
- Scaladoc uniformly looks to field/accessor symbol
- test updates to innerClassAttribute by Lukas
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/analyzerPlugins.check | 49 | ||||
-rw-r--r-- | test/files/run/compiler-asSeenFrom.check | 20 | ||||
-rw-r--r-- | test/files/run/existential-rangepos.check | 2 | ||||
-rw-r--r-- | test/files/run/idempotency-lazy-vals.check | 14 | ||||
-rw-r--r-- | test/files/run/lazy-locals.check | 3 | ||||
-rw-r--r-- | test/files/run/showraw_mods.check | 2 | ||||
-rw-r--r-- | test/files/run/t6023.check | 4 | ||||
-rw-r--r-- | test/files/run/t6733.check | 2 | ||||
-rw-r--r-- | test/files/run/trait-fields-override-lazy.check | 2 | ||||
-rw-r--r-- | test/files/run/trait-fields-override-lazy.scala | 13 |
10 files changed, 58 insertions, 53 deletions
diff --git a/test/files/run/analyzerPlugins.check b/test/files/run/analyzerPlugins.check index ca0005ea4d..9643079b83 100644 --- a/test/files/run/analyzerPlugins.check +++ b/test/files/run/analyzerPlugins.check @@ -1,4 +1,5 @@ adaptBoundsToAnnots(List( <: Int), List(type T), List(Int @testAnn)) [2] +annotationsConform(Boolean @testAnn, Boolean @testAnn) [2] annotationsConform(Boolean @testAnn, Boolean) [1] annotationsConform(Boolean(false), Boolean @testAnn) [1] annotationsConform(Int @testAnn, ?A) [1] @@ -13,7 +14,7 @@ canAdaptAnnotations(Trees$Select, ?) [1] canAdaptAnnotations(Trees$Select, Boolean @testAnn) [1] canAdaptAnnotations(Trees$Select, Boolean) [1] canAdaptAnnotations(Trees$Select, String @testAnn) [1] -canAdaptAnnotations(Trees$TypeTree, ?) [10] +canAdaptAnnotations(Trees$TypeTree, ?) [8] canAdaptAnnotations(Trees$Typed, ?) [3] canAdaptAnnotations(Trees$Typed, Any) [1] canAdaptAnnotations(Trees$Typed, Int) [1] @@ -24,19 +25,19 @@ pluginsPt(?, Trees$ApplyImplicitView) [2] pluginsPt(?, Trees$Block) [4] pluginsPt(?, Trees$ClassDef) [2] pluginsPt(?, Trees$DefDef) [14] -pluginsPt(?, Trees$Ident) [50] +pluginsPt(?, Trees$Ident) [51] pluginsPt(?, Trees$If) [2] pluginsPt(?, Trees$Literal) [16] -pluginsPt(?, Trees$New) [5] +pluginsPt(?, Trees$New) [6] pluginsPt(?, Trees$PackageDef) [1] pluginsPt(?, Trees$Return) [1] -pluginsPt(?, Trees$Select) [43] +pluginsPt(?, Trees$Select) [45] pluginsPt(?, Trees$Super) [2] pluginsPt(?, Trees$This) [13] pluginsPt(?, Trees$TypeApply) [3] pluginsPt(?, Trees$TypeBoundsTree) [2] pluginsPt(?, Trees$TypeDef) [1] -pluginsPt(?, Trees$TypeTree) [38] +pluginsPt(?, Trees$TypeTree) [32] pluginsPt(?, Trees$Typed) [1] pluginsPt(?, Trees$ValDef) [21] pluginsPt(Any, Trees$Literal) [2] @@ -60,7 +61,7 @@ pluginsPt(String, Trees$Ident) [3] pluginsPt(String, Trees$Literal) [1] pluginsPt(String, Trees$Select) [1] pluginsPt(Unit, Trees$Assign) [1] -pluginsPt(testAnn, Trees$Apply) [5] +pluginsPt(testAnn, Trees$Apply) [6] pluginsTypeSig(<none>, Trees$Template) [2] pluginsTypeSig(class A, Trees$ClassDef) [1] pluginsTypeSig(class testAnn, Trees$ClassDef) [1] @@ -70,16 +71,18 @@ pluginsTypeSig(method foo, Trees$DefDef) [1] pluginsTypeSig(method method, Trees$DefDef) [1] pluginsTypeSig(method nested, Trees$DefDef) [1] pluginsTypeSig(type T, Trees$TypeDef) [2] -pluginsTypeSig(value annotField, Trees$ValDef) [2] +pluginsTypeSig(value annotField, Trees$ValDef) [1] +pluginsTypeSig(value count_=, Trees$ValDef) [1] pluginsTypeSig(value f, Trees$ValDef) [1] -pluginsTypeSig(value inferField, Trees$ValDef) [2] -pluginsTypeSig(value lub1, Trees$ValDef) [2] -pluginsTypeSig(value lub2, Trees$ValDef) [2] +pluginsTypeSig(value inferField, Trees$ValDef) [1] +pluginsTypeSig(value lub1, Trees$ValDef) [1] +pluginsTypeSig(value lub2, Trees$ValDef) [1] pluginsTypeSig(value param, Trees$ValDef) [2] pluginsTypeSig(value str, Trees$ValDef) [1] -pluginsTypeSig(value x, Trees$ValDef) [4] -pluginsTypeSig(value y, Trees$ValDef) [4] -pluginsTypeSig(variable count, Trees$ValDef) [3] +pluginsTypeSig(value x, Trees$ValDef) [3] +pluginsTypeSig(value y, Trees$ValDef) [3] +pluginsTypeSig(variable count, Trees$DefDef) [1] +pluginsTypeSig(variable count, Trees$ValDef) [1] pluginsTypeSigAccessor(value annotField) [1] pluginsTypeSigAccessor(value inferField) [1] pluginsTypeSigAccessor(value lub1) [1] @@ -93,7 +96,7 @@ pluginsTyped(()Object, Trees$Select) [1] pluginsTyped(()String, Trees$Ident) [1] pluginsTyped(()String, Trees$TypeApply) [1] pluginsTyped(()scala.annotation.Annotation, Trees$Select) [1] -pluginsTyped(()testAnn, Trees$Select) [10] +pluginsTyped(()testAnn, Trees$Select) [12] pluginsTyped((str: String)A <and> (param: Double)A, Trees$Select) [1] pluginsTyped((x$1: Any)Boolean <and> (x: Double)Boolean <and> (x: Float)Boolean <and> (x: Long)Boolean <and> (x: Int)Boolean <and> (x: Char)Boolean <and> (x: Short)Boolean <and> (x: Byte)Boolean, Trees$Select) [1] pluginsTyped((x$1: Int)Unit, Trees$Select) [1] @@ -122,7 +125,7 @@ pluginsTyped(Any, Trees$TypeTree) [1] 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 @testAnn, Trees$TypeTree) [3] pluginsTyped(Boolean(false), Trees$Literal) [1] pluginsTyped(Boolean, Trees$Apply) [1] pluginsTyped(Boolean, Trees$Select) [3] @@ -139,15 +142,15 @@ pluginsTyped(Int, Trees$Apply) [1] pluginsTyped(Int, Trees$Ident) [1] pluginsTyped(Int, Trees$If) [1] pluginsTyped(Int, Trees$Select) [12] -pluginsTyped(Int, Trees$TypeTree) [13] +pluginsTyped(Int, Trees$TypeTree) [10] pluginsTyped(List[Any], Trees$Apply) [1] pluginsTyped(List[Any], Trees$Select) [1] -pluginsTyped(List[Any], Trees$TypeTree) [3] +pluginsTyped(List[Any], Trees$TypeTree) [2] pluginsTyped(Nothing, Trees$Return) [1] pluginsTyped(Object, Trees$Apply) [1] pluginsTyped(String @testAnn, Trees$Ident) [1] pluginsTyped(String @testAnn, Trees$Select) [1] -pluginsTyped(String @testAnn, Trees$TypeTree) [4] +pluginsTyped(String @testAnn, Trees$TypeTree) [3] pluginsTyped(String(""), Trees$Literal) [2] pluginsTyped(String("huhu"), Trees$Literal) [1] pluginsTyped(String("str") @testAnn, Trees$Typed) [1] @@ -156,13 +159,13 @@ pluginsTyped(String("two"), Trees$Literal) [2] pluginsTyped(String, Trees$Apply) [2] pluginsTyped(String, Trees$Block) [2] pluginsTyped(String, Trees$Select) [7] -pluginsTyped(String, Trees$TypeTree) [7] +pluginsTyped(String, Trees$TypeTree) [6] pluginsTyped(Unit, Trees$Apply) [2] pluginsTyped(Unit, Trees$Assign) [1] pluginsTyped(Unit, Trees$Block) [4] pluginsTyped(Unit, Trees$If) [1] pluginsTyped(Unit, Trees$Literal) [5] -pluginsTyped(Unit, Trees$TypeTree) [1] +pluginsTyped(Unit, Trees$TypeTree) [2] pluginsTyped([A](xs: A*)List[A], Trees$Select) [1] pluginsTyped([T <: Int]=> Int, Trees$Select) [1] pluginsTyped([T0]()T0, Trees$Select) [1] @@ -176,9 +179,9 @@ pluginsTyped(scala.collection.immutable.List.type, Trees$Select) [2] pluginsTyped(scala.collection.immutable.StringOps, Trees$ApplyImplicitView) [2] pluginsTyped(scala.collection.mutable.WrappedArray[Any], Trees$Apply) [1] pluginsTyped(str.type, Trees$Ident) [3] -pluginsTyped(testAnn, Trees$Apply) [5] -pluginsTyped(testAnn, Trees$Ident) [5] -pluginsTyped(testAnn, Trees$New) [5] +pluginsTyped(testAnn, Trees$Apply) [6] +pluginsTyped(testAnn, Trees$Ident) [6] +pluginsTyped(testAnn, Trees$New) [6] pluginsTyped(testAnn, Trees$This) [1] pluginsTyped(testAnn, Trees$TypeTree) [2] pluginsTyped(testAnn.super.type, Trees$Super) [1] diff --git a/test/files/run/compiler-asSeenFrom.check b/test/files/run/compiler-asSeenFrom.check index 7305504115..46ea4d3685 100644 --- a/test/files/run/compiler-asSeenFrom.check +++ b/test/files/run/compiler-asSeenFrom.check @@ -332,11 +332,6 @@ value dZ { // after parser val cD: ll.C[List[T3]] } -value dZ { // after parser - private[this] val cD: ll.C[List[T3]] - val cD: ll.C[List[T3]] -} - value dZ { // after uncurry private[this] val cD: ll.C[List[T3]] val cD(): ll.C[List[T3]] @@ -347,11 +342,9 @@ value dZ { // after erasure val cD(): ll.C } -value jZ { // after parser - def thisI(): I.this.type - def thisC(): C.this.type - def t2(): T2 - def t1(): T1 +value dZ { // after parser + private[this] val cD: ll.C[List[T3]] + val cD: ll.C[List[T3]] } value jZ { // after parser @@ -393,6 +386,13 @@ value jZ { // after flatten def t1(): Object } +value jZ { // after parser + def thisI(): I.this.type + def thisC(): C.this.type + def t2(): T2 + def t1(): T1 +} + method kz { // after parser def thisI(): I.this.type def thisC(): C.this.type diff --git a/test/files/run/existential-rangepos.check b/test/files/run/existential-rangepos.check index 1212b60bae..984baeaaf8 100644 --- a/test/files/run/existential-rangepos.check +++ b/test/files/run/existential-rangepos.check @@ -7,7 +7,7 @@ }; [24:51]private[this] val foo: [28]Set[_ <: T] = [47:51]null; [28]<stable> <accessor> def foo: [28]Set[_ <: T] = [28][28]A.this.foo; - [54:74]<stable> <accessor> def bar: [58]Set[_ <: T] + [54:74]<stable> <accessor> val bar: [58]Set[_ <: T] } } diff --git a/test/files/run/idempotency-lazy-vals.check b/test/files/run/idempotency-lazy-vals.check index 15afa5303c..3a6f1a7ef0 100644 --- a/test/files/run/idempotency-lazy-vals.check +++ b/test/files/run/idempotency-lazy-vals.check @@ -5,19 +5,11 @@ C.super.<init>(); () }; - lazy private[this] val x: Int = _; - <stable> <accessor> lazy def x: Int = { - C.this.x = 2; - C.this.x - }; - lazy private[this] val y: Int = _; - implicit <stable> <accessor> lazy def y: Int = { - C.this.y = 3; - C.this.y - } + <stable> <accessor> lazy val x: Int = 2; + implicit <stable> <accessor> lazy val y: Int = 3 }; val c: C = new C(); import c._; c.x.*(Predef.implicitly[Int](c.y)) } -error! +6 diff --git a/test/files/run/lazy-locals.check b/test/files/run/lazy-locals.check index 4565326bea..0a3a85ead6 100644 --- a/test/files/run/lazy-locals.check +++ b/test/files/run/lazy-locals.check @@ -1,9 +1,6 @@ lazy-locals.scala:153: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses { ^ -lazy-locals.scala:159: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses - { - ^ forced lazy val q q = 10 forced lazy val t diff --git a/test/files/run/showraw_mods.check b/test/files/run/showraw_mods.check index ff77d22adf..5afd7a438f 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(())))), 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(()))) +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"))), 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/t6023.check b/test/files/run/t6023.check index ee93565234..dd6d8f1f1c 100644 --- a/test/files/run/t6023.check +++ b/test/files/run/t6023.check @@ -1,12 +1,12 @@ { abstract trait Foo extends AnyRef { - <stable> <accessor> def a: Int + val a: Int }; () } { abstract trait Foo extends AnyRef { - <stable> <accessor> def a: Int + <stable> <accessor> val a: Int }; () } diff --git a/test/files/run/t6733.check b/test/files/run/t6733.check index 7062301c56..811a7d8f70 100644 --- a/test/files/run/t6733.check +++ b/test/files/run/t6733.check @@ -4,7 +4,6 @@ method pri2a: isPrivateThis = true, isProtectedThis = false variable pri3a: 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 @@ -18,7 +17,6 @@ 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 class Pro6: isPrivateThis = false, isProtectedThis = true diff --git a/test/files/run/trait-fields-override-lazy.check b/test/files/run/trait-fields-override-lazy.check new file mode 100644 index 0000000000..9e4a9fe6c2 --- /dev/null +++ b/test/files/run/trait-fields-override-lazy.check @@ -0,0 +1,2 @@ +warning: there was one feature warning; re-run with -feature for details +ok diff --git a/test/files/run/trait-fields-override-lazy.scala b/test/files/run/trait-fields-override-lazy.scala new file mode 100644 index 0000000000..2c1cf0e3b0 --- /dev/null +++ b/test/files/run/trait-fields-override-lazy.scala @@ -0,0 +1,13 @@ +trait T { + protected lazy val lv: Boolean = ??? +} + +object Test extends App { + val overrideLazy = new T { + override lazy val lv = true + def foo = lv + } + + assert(overrideLazy.foo) + println("ok") +} |