Is open modifier needed for accessing properties in super class?


#1

I'm having an abstract class Input extending abstract class EmptyElement which extends abstract class Element. They all reside in the same package.

 
public abstract class Input(val type: String?, var value: String? = null, id: String? = null) :
        EmptyElement(name = "input", id = id) {

  val htmlInputElement: HTMLInputElement = super.htmlElement as HTMLInputElement;

  init {
  this.htmlElement.setAttribute(“type”, type);
  if ( value != null ) {
           this.htmlInputElement.value = value!!
  }
  }
}


However the call above fails:

/uploads/kotlinlang/original/1X/359cb8c6be2e40c1895742dbb66da4b9d02563cc.png

Unless I’ve declared property htmlElement of class Element “open”:

public abstract class Element (name: String?,
                               cssClass: String? = null,
                               id: String? = null,
                               htmlElement: HTMLElement? = null) {

  open val htmlElement: HTMLElement = htmlElement ?: document.createElement(name) as HTMLElement;


<pre><span >...</code></pre>
}


Empty/uploads/kotlinlang/original/1X/836dd12ace62c834a0de7313dd1bb821a7f6820b.zip (299 Bytes)

Element.kt.zip (504 Bytes)

#2

i'm using version "0.1-SNAPSHOT"


#3

I can't reproduce it.

Could you please provide full project or simplified project?

Thanks!


#4

I reproduced the problem, and I'll create issue about it soon.

Let us know if you need help to workaround it.


#5

Great!

Thanks. I guess the workaround is to keep it open.


#6

I created issue KT-7653. Feel free to vote or star it to get updates.