Repository navigation
RegisterProperty: opt-in check for properties with an unresolved type - #307
TetzkatLipHoka wants to merge 2 commits into
Conversation
TPSCompileTimeClass.RegisterProperty freed the half-built property and returned silently when its type string referenced a type that was not (yet) registered. Scripts using the property then failed with a bare 'Unknown identifier' - very hard to trace back to a wrong registration order in an import unit. This is the actual root cause behind reports like issue remobjects#255 ('Delphi 11 case sensitive'). Raise EPSCompilerException naming the property and its type string instead, matching how AddTypeS and the other registration APIs report bad input. Inside OnUses the exception surfaces as a regular compiler error message. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
We tried this change downstream (Delphi 13, current master plus a few fixes) as a check of our own registrations, and as it stands it breaks the stock Classes import.
{$IFDEF DELPHI3UP} RegisterProperty('ItemClass', 'TCollectionItemClass', iptr); {$ENDIF}
In our case that was every script. Before the raise, we logged every property Two things the PR would need:
|
The unconditional raise broke every host importing stock units: the first victim is TCollection.ItemClass in uPSC_classes (reported on the PR), but logging all drops shows the stock import units lose about 50 properties, many of them on purpose - TControl.PopupMenu without the Menus import, for example, or anything registered before its type's unit. Dropping is what those units rely on, so it has to stay the default. Add TPSPascalCompiler.StrictPropertyRegistration for hosts that want to check their own registrations; it raises naming the property and its type. The published-property helpers never raise: RegisterPublishedProperties skips types scripts do not know, and RegisterPublishedProperty now returns False for them instead of reporting success for a dropped property. Repro: register SIRegister_Classes in OnUses and compile 'begin end.'. Before: 'Unable to register type ItemClass: TCollectionItemClass'. After: compiles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for testing this, you were right, and it goes further: with all stock import units registered, 40 to 52 properties get dropped depending on registration order (for example |
TPSCompileTimeClass.RegisterProperty frees the half-built property and returns
silently when its type string references a type that is not (yet) registered.
Scripts using the property then fail with a bare 'Unknown identifier', which is
very hard to trace back to a wrong registration order in an import unit. This is
the actual root cause behind reports like issue #255 ('Delphi 11 case sensitive').
Dropping has to stay the default. An earlier version of this PR raised
unconditionally, which broke every host importing Classes (
TCollection.ItemClass,see the comments). With all stock import units registered, 40 to 52 properties are
dropped depending on registration order, for example
PopupMenuwithout the Menusimport, so those units rely on it.
Changes:
TPSPascalCompiler.StrictPropertyRegistration(default False) makesRegisterProperty raise EPSCompilerException naming the property and its type
string. It is meant to be enabled around a host's own registrations; inside OnUses
the exception surfaces as a regular compiler error message.
RegisterPublishedPropertiesskips published properties of a type scripts do notknow, also in strict mode.
RegisterPublishedPropertyreturns False for such a property instead of reportingsuccess for a dropped one.
Repro:
SIRegister_Classesin OnUses, compilebegin end.: compiles, as on master.StrictPropertyRegistration := True, thenRegisterProperty('BrokenProp', 'TUnknownType', iptRW):Unable to register type BrokenProp: TUnknownType.Verified with a probe on Delphi 12.3, Win32 and Win64. The test suite PR (#317)
now covers the default behaviour and the stock Std and Classes imports.
Related to #255 (the reported "case sensitivity" is actually this silent registration
failure: the property is dropped and the script then fails with Unknown identifier).
🤖 Generated with Claude Code