Hello folks. So, following on the advice I got her...
# announcements
g
Hello folks. So, following on the advice I got here about the snippets I posted yesterday (https://kotlinlang.slack.com/files/gregschlom/F1N0ZHWUC/Can_somebody_take_a_look_at_this_and_explain_the_behavior_that_I___m_seeing__Is_that_a_language_bug_.kt), I decompiled the code to look at what was generated. Snippet 1 gives this:
Copy code
public final class Foo {
	   private int a = 2;

	   public final int getA() {
	      return this.a;
	   }

	   public final void setA(int value) {
	      Log.i("##", "setter called with: " + value);
	      this.a = value;
	   }
	}
Snippet 3 and 4 give this:
Copy code
public final class Foo {
	   private int a;

	   public final int getA() {
	      return this.a;
	   }

	   public final void setA(int value) {
	      Log.i("##", "setter called with: " + value);
	      this.a = value;
	   }

	   public Foo() {
	      this.setA(2);
	   }
	}
`
- So ok, I understand Snippet 1: the backing field is initialized directly, bypassing the setter. This is a little bit counter-intuitive and should probably be documented on https://kotlinlang.org/docs/reference/properties.html - The generated code for snippet 3 and snippet 4 is identical, and I see no reason why snippet 2 would not compile. Therefore I think this should be categorized as a compiler bug.