projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.83k stars 2.37k forks source link

@val and @Delegate combined cause an error compiling with javac #636

Open lombokissues opened 9 years ago

lombokissues commented 9 years ago

Migrated from Google Code (issue 601)

lombokissues commented 9 years ago

:bust_in_silhouette: gss222   :clock8: Oct 31, 2013 at 21:24 UTC

What steps will reproduce the problem?

The following class does not compile under javac using lombok but it does on Eclipse. The problem seems to arise from mixing usage of @ val and @ Delegate in a parent-child relationship.

import lombok.Delegate; import lombok.val;

public class Main { public static void main(String[] args) { val bomb = new Bomb(); bomb.arm(); }

public static class Bomb { @ Delegate private Detonator detonator = new Detonator();

  private Timer timer = new Timer();

  public void arm()
  {
     this.timer.bomb = this;
     this.timer.start();
  }

}

public static class Detonator { public Trigger getTrigger() { return new Trigger(); } }

public static class Timer { private Bomb bomb;

  public void start()
  {
     val trigger = bomb.getTrigger();

     trigger.detonate();
  }

}

public static class Trigger { public void detonate() { System.out.println("BOOM!!"); } } }

What is the expected output? What do you see instead?

The error message returned is:

Main.java:46: error: Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved val something = parent.getSomething(); ^ 1 error

What version of the product are you using? On what operating system?

Lombok Version 1.12.2, JDK 7

lombokissues commented 9 years ago

:bust_in_silhouette: gss222   :clock8: Oct 31, 2013 at 21:24 UTC

:link: Main.java View file

lombokissues commented 9 years ago

:bust_in_silhouette: gss222   :clock8: Oct 31, 2013 at 21:29 UTC

The error should be

Main.java:40: error: Cannot use 'val' here because initializer expression does not have a representable type: Type cannot be resolved val trigger = bomb.getTrigger();

lombokissues commented 9 years ago

End of migration

michalsustr commented 6 years ago

Confirming this is still an issue.

kylerjensen commented 5 years ago

Experiencing this issue in IntelliJ IDEA Ultimate 2018.2