Skip to content

Instantly share code, notes, and snippets.

@alextkachman
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alextkachman/9802138 to your computer and use it in GitHub Desktop.
Save alextkachman/9802138 to your computer and use it in GitHub Desktop.
Failing kotlin2js codegen for delegated extension properties
// Kotlin example
class Delegate() {
fun get(obj: String, desc: PropertyMetadataImpl) : String = obj.toString() + ".log"
}
val String.log by Delegate()
fun main(args : Array<String>) {
println("Hello, world!".log)
}
// Here is generated JS
Kotlin.System.flush();
(function () {
'use strict';
var _ = Kotlin.defineRootPackage(function () {
this.log$delegate = new _.Delegate();
}, /** @lends _ */ {
Delegate: Kotlin.createClass(null, null, /** @lends _.Delegate.prototype */ {
get: function (obj, desc) {
return obj + '.log';
}
}),
get_log: {value: function () {
// BUG: $receiver omited and ignored
return this.log$delegate.get(this, new Kotlin.PropertyMetadata('log'));
}},
main: function (args) {
Kotlin.println(_.get_log('Hello, world!'));
}
});
Kotlin.defineModule('JS_TESTS', _);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment