The following code produces internal compiler error:
namespace TestEnumIndex;
uses
java.util;
type
TestEnum = public enum (One, Two, Three) of java.lang.Enum;
// TestEnumArray = array [TestEnum] of Integer;// (E225) "TestEnum" is not a valid type for array ranges TestEnumIndex
TestEnumArray = array [low(TestEnum) .. high(TestEnum)] of Integer;
type
Program = class
public
class method Main(args: array of String): Int32;
begin
var arr: TestEnumArray;
arr[TestEnum.One] := 22;
// The above line gives:
//Severity Code Description Project File Line Suppression State
//Error (E0) Internal error: System.NullReferenceException: Object reference not set to an instance of an object.
// at RemObjects.Oxygene.Code.ArrayAccessExpressionTransform.ResolveExpression(ScopeInfo aScope, ArrayAccessExpression array)
// at RemObjects.Oxygene.Code.Compiler.NewResolveExpressionAndStatement.VisitExpression(ScopeInfo aScope, Expression element)
// at RemObjects.Oxygene.Code.AssignmentStatementTransform.ResolveStatement(ScopeInfo aScope, AssignmentStatement assignmentStatement)
// at RemObjects.Oxygene.Code.Compiler.NewResolveExpressionAndStatement.VisitStatement(ScopeInfo aScope, Statement element)
// at RemObjects.Oxygene.Code.BeginStatementTransform.ResolveStatement(ScopeInfo aScope, BeginStatement beginStatement)
// at RemObjects.Oxygene.Code.Compiler.NewResolveExpressionAndStatement.VisitStatement(ScopeInfo aScope, Statement element)
// at RemObjects.Oxygene.Code.Compiler.ResolveMembersCompiler.ResolveMethodBody(ScopeInfo aScope, IMethodImplementation aMethod)
// at RemObjects.Oxygene.Code.Compiler.ResolveMembersCompiler.<>c__DisplayClass14.<ResolveMembers>b__5(IParsedType aType)
// at RemObjects.Oxygene.Code.Compiler.Compiler.ForAllInternalTypes(Action`1 aAt)
// at RemObjects.Oxygene.Code.Compiler.ResolveMembersCompiler.ResolveMembers__$mapped(Compiler self) TestEnumIndex D:\RemObjects\TestEnumIndex\Program.pas 19
end;
end;
end.
There is enough information in the code and the proof is my software that uses both features and runs perfectly in Elements.2409. I understand that you redesigned enums after that, but this broke a lot of my code and took away the functionality which is, I believe, not essential just for me, but for the clarity of Oxygene in general.
I know I can make a tiny stringlist for each declared enum and search through the list to match the string with the corresponding enum value. But I don’t want to do this because:
(1) This requires a manual declaration of a string list for each and every declared enum type (which I have many),
(2) this clutters the code and
(3) makes it less manageable, as the same information is entered twice in two places,
(4) and is simply a shameful workaround for a high-level language claiming to support enums.
I spent a lot of time trying to find a suitable solution myself, and failed. I also spent a lot of effort to communicate the issue with you and explain why it is important for me and Oxygene in general. I apparently failed, too. However, please don’t chase me away with the “impossible” argument, I am not buying it. I know the solution is possible. It was possible in Elements.2409. If I can make those tiny string lists myself, I see no reason why the compiler cannot make them silently for me behind the scenes. It does have all the information in the code and it is your compiler, FGS.
I give up. Until this is resolved, I am stuck with Elements.2409.
@markobohanec so this was actually broken too in 2409 and would always return 0. But I think I have a plan of attack now. I’ll see what I can do later this week to tackle this.