commented out delegate creation

This commit is contained in:
Sergey Chernov 2025-08-14 14:34:44 +03:00
parent b07452e66e
commit eca746b189

View File

@ -1792,7 +1792,7 @@ class Compiler(
// when creating instance, but we need to execute it in the class initializer which // when creating instance, but we need to execute it in the class initializer which
// is missing as for now. Add it to the compiler context? // is missing as for now. Add it to the compiler context?
if (isDelegate) throw ScriptError(start, "static delegates are not yet implemented") // if (isDelegate) throw ScriptError(start, "static delegates are not yet implemented")
currentInitScope += statement { currentInitScope += statement {
val initValue = initialExpression?.execute(this)?.byValueCopy() ?: ObjNull val initValue = initialExpression?.execute(this)?.byValueCopy() ?: ObjNull
(thisObj as ObjClass).createClassField(name, initValue, isMutable, visibility, pos) (thisObj as ObjClass).createClassField(name, initValue, isMutable, visibility, pos)
@ -1807,23 +1807,24 @@ class Compiler(
throw ScriptError(nameToken.pos, "Variable $name is already defined") throw ScriptError(nameToken.pos, "Variable $name is already defined")
if (isDelegate) { if (isDelegate) {
println("initial expr = $initialExpression") TODO()
val initValue = // println("initial expr = $initialExpression")
(initialExpression?.execute(context.copy(Arguments(ObjString(name)))) as? Statement) // val initValue =
?.execute(context.copy(Arguments(ObjString(name)))) // (initialExpression?.execute(context.copy(Arguments(ObjString(name)))) as? Statement)
?: context.raiseError("delegate initialization required") // ?.execute(context.copy(Arguments(ObjString(name))))
println("delegate init: $initValue") // ?: context.raiseError("delegate initialization required")
if (!initValue.isInstanceOf(ObjArray)) // println("delegate init: $initValue")
context.raiseIllegalArgument("delegate initialized must be an array") // if (!initValue.isInstanceOf(ObjArray))
val s = initValue.getAt(context, 1) // context.raiseIllegalArgument("delegate initialized must be an array")
val setter = if (s == ObjNull) statement { raiseNotImplemented("setter is not provided") } // val s = initValue.getAt(context, 1)
else (s as? Statement) ?: context.raiseClassCastError("setter must be a callable") // val setter = if (s == ObjNull) statement { raiseNotImplemented("setter is not provided") }
ObjDelegate( // else (s as? Statement) ?: context.raiseClassCastError("setter must be a callable")
(initValue.getAt(context, 0) as? Statement) // ObjDelegate(
?: context.raiseClassCastError("getter must be a callable"), setter // (initValue.getAt(context, 0) as? Statement)
).also { // ?: context.raiseClassCastError("getter must be a callable"), setter
context.addItem(name, isMutable, it, visibility, recordType = ObjRecord.Type.Field) // ).also {
} // context.addItem(name, isMutable, it, visibility, recordType = ObjRecord.Type.Field)
// }
} else { } else {
// init value could be a val; when we initialize by-value type var with it, we need to // init value could be a val; when we initialize by-value type var with it, we need to
// create a separate copy: // create a separate copy: