View Issue Details

IDProjectCategoryView StatusLast Update
0037001FPCCompilerpublic2020-04-30 16:03
ReporterKai Burghardt Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformx86_64OSGNU/Linux 
Product Version3.0.4 
Summary0037001: default array property for non-classes
DescriptionOne can declare an array property as a default property, even though it is not a member of a class.
Steps To ReproduceI wanted to do something like in the attached file.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Kai Burghardt

2020-04-30 16:00

reporter  

defaultPropertyForTypeHelper.pas (750 bytes)   
program defaultPropertyForTypeHelper(input, output, stdErr);
{$modeSwitch typeHelpers+}
type
	attribute = (foo, bar, foobarable, xyz);
	attributes = set of attribute;
	attributeGroup = (black, white);
	attributeHelper = type helper for attributes
			function getAttributesByGroup(const g: attributeGroup): attributes;
			property byGroup[g: attributeGroup]:
				attributes read getAttributesByGroup; default;
		end;

function attributeHelper.getAttributesByGroup(
		const g: attributeGroup
	): attributes;
begin
	case g of
		black:
		begin
			getAttributesByGroup := [foo, xyz];
		end;
		white:
		begin
			getAttributesByGroup := [bar, foobarable];
		end;
	end;
end;

var
	a: attributes;
begin
	a := [foo, bar, foobarable, xyz];
	a := a[black];
end.

Kai Burghardt

2020-04-30 16:03

reporter   ~0122564

Oups. Minor implementation mistake. But I think you get the idea.
defaultPropertyForTypeHelper-2.pas (764 bytes)   
program defaultPropertyForTypeHelper(input, output, stdErr);
{$modeSwitch typeHelpers+}
type
	attribute = (foo, bar, foobarable, xyz);
	attributes = set of attribute;
	attributeGroup = (black, white);
	attributeHelper = type helper for attributes
			function getAttributesByGroup(const g: attributeGroup): attributes;
			property byGroup[g: attributeGroup]:
				attributes read getAttributesByGroup; default;
		end;

function attributeHelper.getAttributesByGroup(
		const g: attributeGroup
	): attributes;
begin
	case g of
		black:
		begin
			getAttributesByGroup := self * [foo, xyz];
		end;
		white:
		begin
			getAttributesByGroup := self * [bar, foobarable];
		end;
	end;
end;

var
	a: attributes;
begin
	a := [foo, bar, foobarable, xyz];
	a := a[black];
end.

Issue History

Date Modified Username Field Change
2020-04-30 16:00 Kai Burghardt New Issue
2020-04-30 16:00 Kai Burghardt File Added: defaultPropertyForTypeHelper.pas
2020-04-30 16:03 Kai Burghardt Note Added: 0122564
2020-04-30 16:03 Kai Burghardt File Added: defaultPropertyForTypeHelper-2.pas