Property extensions

I'm working on adding a property extension. For example:

package foo;

val Date.ima : String

  get() = "This is a date"

This works fine, and I can call it as follows:

import java.util.Date

import foo.ima

fun main(args: Array<String>) {

  var d = Date()

  println(d.ima)

}

However, I’m doing something a little more interesting, so I add this to the first file:

val String.ima : String

  get() = "This is a string"

Now, if I attempt to use both, I get an error:

import java.util.Date import foo.ima

fun main(args: Array<String>) {
  var d = Date()
  var s = “Something…”

  println(d.ima)
  println(s.ima)

}

Error(10,13)  Kotlin: Type mismatch: inferred type is java.util.Date but jet.String was expected

When you have to function extensions of the same name, things seem to work fine, but with 2 value extensions, there are problems.

If I'm understood. Code look like this

file foo.kt

package foo

import java.util.Date

val Date.ima: String
  get() = “This is a date”

val String.ima: String
  get() = “This is a string”


file test.kt

package test

import foo.ima
import java.util.Date

fun main(args: Array<String>) {
  var d = Date()
  var s = “Something…”

  println(d.ima)
  println(s.ima)
}


And it is bug, I think

You are right, it's a bug. Please report it to your bug tracker (http://youtrack.jetbrains.com). As a workaround, you can write "foo.*" to import all properties from package foo.