Forbid subclasses of NativePointed to have backing fields

(this crashes the compiler otherwise)
This commit is contained in:
Svyatoslav Scherbina
2020-11-02 16:40:10 +03:00
committed by Stanislav Erokhin
parent 2ce2565e8f
commit d218b88106
2 changed files with 21 additions and 0 deletions
@@ -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)
}