Test for native property accessors
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
class C {
|
||||
class object {
|
||||
val defaultGetter: Int = 1
|
||||
[native] get
|
||||
|
||||
var defaultSetter: Int = 1
|
||||
[native] get
|
||||
[native] set
|
||||
}
|
||||
|
||||
val defaultGetter: Int = 1
|
||||
[native] get
|
||||
|
||||
var defaultSetter: Int = 1
|
||||
[native] get
|
||||
[native] set
|
||||
}
|
||||
|
||||
val defaultGetter: Int = 1
|
||||
[native] get
|
||||
|
||||
var defaultSetter: Int = 1
|
||||
[native] get
|
||||
[native] set
|
||||
|
||||
fun check(body: () -> Unit, signature: String): String? {
|
||||
try {
|
||||
body()
|
||||
return "Link error expected"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
if (e.getMessage() != signature) return "Fail $signature: " + e.getMessage()
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return check({defaultGetter}, "_DefaultPackage.getDefaultGetter()I")
|
||||
?: check({defaultSetter = 1}, "_DefaultPackage.setDefaultSetter(I)V")
|
||||
|
||||
?: check({C.defaultGetter}, "C\$object.getDefaultGetter()I")
|
||||
?: check({C.defaultSetter = 1}, "C\$object.setDefaultSetter(I)V")
|
||||
|
||||
?: check({C().defaultGetter}, "C.getDefaultGetter()I")
|
||||
?: check({C().defaultSetter = 1}, "C.setDefaultSetter(I)V")
|
||||
|
||||
?: "OK"
|
||||
}
|
||||
+6
@@ -1825,6 +1825,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nativePropertyAccessors.kt")
|
||||
public void testNativePropertyAccessors() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/native/nativePropertyAccessors.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleNative.kt")
|
||||
public void testSimpleNative() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/native/simpleNative.kt");
|
||||
|
||||
@@ -50,10 +50,18 @@ A native member of package `p` yields one JVM method:
|
||||
### Native Property Accessors
|
||||
|
||||
A property can not be marked `native`.
|
||||
A *property accessor* can be marked `native`. In this case the generated code is the same as for a native function defined in the same
|
||||
context as the property.
|
||||
A *property accessor* can be marked `native` if it has no body (i.e. it is a *default accessor*).
|
||||
In this case the generated code is the same as for a native function defined in the same context as the property.
|
||||
|
||||
Example:
|
||||
``` kotlin
|
||||
val foo: Int
|
||||
[native] get
|
||||
```
|
||||
|
||||
## Not implemented (yet)
|
||||
|
||||
- native property accessors
|
||||
- frontend: when accessors are default and native, don't require an initializer, don't allow a backing field
|
||||
- backend: when accessors are default and native, don't generate a backing field
|
||||
- applicability checks: only functions and property accessors
|
||||
Reference in New Issue
Block a user