Skip to content

annotation.targetName makes trait "lazy val" a "def" #13358

Closed
@edolgy

Description

@edolgy

Compiler version

3.0.2-RC1

Minimized code

object Test:
  var cnt = 0

  trait Foo:
    lazy val foo1 = {cnt+=1; cnt}
    
    @scala.annotation.targetName("fooTwo") 
    lazy val foo2 = {cnt+=1; cnt}

  object Bar extends Foo

  def main(sa: Array[String]): Unit =

    println(Bar.foo1)  // Prints 1
    println(Bar.foo1)  // Prints 1
    println(Bar.foo1)  // Prints 1
    println(Bar.foo1)  // Prints 1

    println(Bar.foo2)  // Prints 2  
    println(Bar.foo2)  // Prints 3  EXPECTED 2
    println(Bar.foo2)  // Prints 4  EXPECTED 2
    println(Bar.foo2)  // Prints 5  EXPECTED 2

This issue might be related to 13252

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions