Forbid subclasses of NativePointed to have backing fields
(this crashes the compiler otherwise)
This commit is contained in:
committed by
Stanislav Erokhin
parent
2ce2565e8f
commit
d218b88106
+11
@@ -321,6 +321,17 @@ private class BackendChecker(val context: Context, val irFile: IrFile) : IrEleme
|
||||
reportError(expression, "Native interop types constructors must not be called directly")
|
||||
}
|
||||
|
||||
override fun visitField(declaration: IrField) {
|
||||
if (declaration.isFakeOverride) return // Can't happen now, just trying to be future-proof here.
|
||||
|
||||
val parent = declaration.parent
|
||||
|
||||
if (parent is IrClass && parent.defaultType.isNativePointed(symbols) && parent.symbol != symbols.nativePointed) {
|
||||
val nativePointed = symbols.nativePointed.owner.name
|
||||
reportError(declaration, "Subclasses of $nativePointed cannot have properties with backing fields")
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitCall(expression: IrCall) {
|
||||
expression.acceptChildrenVoid(this)
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
class Vertex constructor(rawPtr: NativePtr) : CStructVar(rawPtr) {
|
||||
var x: Float = 0f
|
||||
var y: Float = 0f
|
||||
var r: Float = 0f
|
||||
var g: Float = 0f
|
||||
var b: Float = 0f
|
||||
companion object : CStructVar.Type(40, 8)
|
||||
}
|
||||
Reference in New Issue
Block a user