Aspects Seem broken in 2249

I have a large number of aspects that I have been using successfully for a number of years

but now whenever I try and use it (First time in the version 10 compiler) I get

error E238: Exception while applying aspect “xxxxxxAttribute”: Object reference not set to an instance of an object.

I even went back to the singleton sample aspect that you supplied a few years ago

namespace Nutcracker.CMS4.Utilities.Aspects;

interface

uses
System.Collections.Generic,
System.Text,
RemObjects.Oxygene.Cirrus.*;

type
[AttributeUsage(AttributeTargets.Class)]
SingletonAttribute = public class (Attribute, ITypeInterfaceDecorator, ITypeImplementationDecorator{, IMethodImplementationDecorator})
private
const instanceFieldName = ‘theInstance’;
const instanceGetterName = ‘get_Instance’;
const instancePropertyName = ‘Instance’;
method CheckForSingleNoParameterConstructor(Services: IServices; ctors: Array of IMethod): Boolean;
method CheckForAvailableFieldGetterAndPropertyNames(Services: IServices; aType: ITypeDefinition): Boolean;
public
method HandleInterface(Services: IServices; aType: ITypeDefinition);
method HandleImplementation(Services: IServices; aMethod: IMethodDefinition);
method HandleImplementation(Services: IServices; aType: ITypeDefinition);
end;

implementation

method SingletonAttribute.HandleInterface(Services: IServices; aType: ITypeDefinition);
begin
if not CheckForAvailableFieldGetterAndPropertyNames(Services, aType) then
exit;
var constructors: Array of IMethod := aType.GetConstructors();
if not CheckForSingleNoParameterConstructor(Services, constructors) then
exit;
IMethodDefinition(constructors[0]).Visibility := Visibility.Private;
aType.AddField(instanceFieldname, aType, true);
var instanceGetter: IMethodDefinition := aType.AddMethod(instanceGetterName, aType, true);
instanceGetter.Visibility := Visibility.Public;
var instanceProperty: IPropertyDefinition := aType.AddProperty(instancePropertyName, aType, true);
instanceProperty.Visibility := Visibility.Public;
instanceProperty.ReadMethod := instanceGetter;
end;

method SingletonAttribute.HandleImplementation(Services: IServices; aMethod: IMethodDefinition);
begin
if aMethod.Name = instanceGetterName then
begin
// services.EmitWarning('Adding Implementation '+instanceGetterName);
aMethod.SetBody(Services, method
begin
if not Assigned(unquote(new StaticValue(aMethod.Owner, instanceFieldName))) then
begin
unquote(new StaticValue(aMethod.Owner, instanceFieldName)) := unquote(new NewValue(aMethod.Owner));
end;
exit unquote(new StaticValue(aMethod.Owner, instanceFieldName));
end);
end
// else
// services.EmitWarning('No changes to Implementation '+aMethod.name);
end;

method SingletonAttribute.CheckForSingleNoParameterConstructor(Services: IServices; ctors: Array of IMethod): Boolean;
begin
if not (ctors.Length = 1) then
begin
Services.EmitError(‘Singleton Aspect can only be applied to classes with a single constructor.’);
exit false;
end;
if not (ctors[0].Visibility = Visibility.Public) then
begin
Services.EmitError(‘Singleton Aspect can only be applied to classes with a public constructor.’);
exit false;
end;
if not (ctors[0].ParameterCount = 0) then
begin
Services.EmitError(‘Singleton Aspect can only be applied to classes with a parameterless constructor.’);
exit false;
end;
exit true;
end;

method SingletonAttribute.CheckForAvailableFieldGetterAndPropertyNames(Services: IServices; aType: ITypeDefinition): Boolean;
begin
if Assigned(aType.GetStaticField(instanceFieldName)) then
begin
Services.EmitError(String.Format(‘Singleton Aspect can only be applied to classes without a field called “{0}”.’, instanceFieldName));
exit false;
end;
if (aType.GetStaticMethods(instanceGetterName).Length > 0)
or (aType.GetMethods(instanceGetterName).Length > 0) then
begin
Services.EmitError(String.Format(‘Singleton Aspect can only be applied to classes without a method called “{0}”.’, instanceGetterName));
exit false;
end;
if (aType.GetProperties(instancePropertyName).Length > 0)
or (aType.GetStaticProperties(instancePropertyName).Length > 0) then
begin
Services.EmitError(String.Format(‘Singleton Aspect can only be applied to classes without a property called “{0}”.’, instancePropertyName));
exit false;
end;
exit true;
end;

method SingletonAttribute.HandleImplementation(Services: IServices; aType: ITypeDefinition);
begin
for i : integer := 0 to aType.MethodCount-1 do
HandleImplementation(Services,aType.GetMethod(i));
end;

end.

in this small sample app

namespace ConsoleApplication1;

interface

uses
nutcracker.CMS4.Utilities.Aspects,
System.Linq;

type
[SingletonAttribute]
test = class
private

public
method Show;
end;
Program = class
public
class method Main(args: array of String): Int32;
end;

implementation

class method Program.Main(args: array of String): Int32;
begin
test.Instance.Show;
writeLn(‘The magic happens here.’);
end;

method test.Show;
begin
end;

end.

to the same effect

Thanks, logged as bugs://79644

Thanks; fixed for tomorrows build.

bugs://79644 got closed with status fixed.