Consider the following example code.
using { /Verse.org/Random }
base_class := class<unique><concrete>:
Name:string = ""
subclass_a := class(base_class):
ValueA:int = 123
subclass_b := class(base_class):
ValueB:float = 456.0
subclass_c := class(base_class):
ValueC:string = "789"
UsageExample():void =
ClassType := base_class
Instance := ClassType: # type(base_class, base_class)
Name := "Wobbles"
Print("Created an object named '{Instance.Name}'")
SubclassType := subclass_a
SubclassInstance := SubclassType: # type(subclass_a, subclass_a)
Name := "Chuckles"
ValueA := 99
Print("Created an object named '{SubclassInstance.Name}' with value '{SubclassInstance.ValueA}'")
AllSubclassTypes := array:
subclass_a
subclass_b
subclass_c
RandomIndex := GetRandomInt(0, AllSubclassTypes.Length - 1)
if (SelectedType := AllSubclassTypes[RandomIndex]):
SelectedType{} # FAILS with "false is not a macro.(3545)"
The compiler fails at the commented line stating “false is not a macro”
It seems like the array is of type []subtype(base_class)
and hence SelectedType is of type subtype(base_class)
This differs from the types noted in the previous tests and seems to be the cause of the problem. I suspect that this is currently unsupported, but thought I would ask just in case I’m missing something.
Does anyone know how to wrangle the selection back into a type that can be instantiated or which type should be used to store the subtypes in the first place?