Skip to content

RegisterProperty: opt-in check for properties with an unresolved type - #307

Open
TetzkatLipHoka wants to merge 2 commits into
remobjects:masterfrom
TetzkatLipHoka:fix/registerproperty-silent-failure
Open

TetzkatLipHoka wants to merge 2 commits into
remobjects:masterfrom
TetzkatLipHoka:fix/registerproperty-silent-failure

Conversation

@TetzkatLipHoka

@TetzkatLipHoka TetzkatLipHoka commented Jul 11, 2026 •

Copy link
Copy Markdown

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 PopupMenu without the Menus
import, so those units rely on it.

Changes:

  • TPSPascalCompiler.StrictPropertyRegistration (default False) makes
    RegisterProperty 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.
  • RegisterPublishedProperties skips published properties of a type scripts do not
    know, also in strict mode.
  • RegisterPublishedProperty returns False for such a property instead of reporting
    success for a dropped one.

Repro:

  • SIRegister_Classes in OnUses, compile begin end.: compiles, as on master.
  • StrictPropertyRegistration := True, then
    RegisterProperty('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

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>
@Vizit0r

Vizit0r commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

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.

uPSC_classes.pas, SIRegisterTCOLLECTION:

{$IFDEF DELPHI3UP}  RegisterProperty('ItemClass', 'TCollectionItemClass', iptr); {$ENDIF}

TCollectionItemClass is never registered on the compiler side (its only other mention is the commented-out constructor), so today this property is silently dropped. With the raise from this PR, SIRegister_Classes throws instead, and every compile that imports Classes fails:

[Error] (1:1): Unable to register type ItemClass: TCollectionItemClass

In our case that was every script. Before the raise, we logged every property RegisterProperty drops while compiling against our full API: TCollection.ItemClass was the only one, so the diagnostic idea itself is useful.

Two things the PR would need:

  1. Fix or remove the ItemClass registration in uPSC_classes first (register TCollectionItemClass, or drop the property).
  2. Keep RegisterPublishedProperties silent. It registers every published property of a class from RTTI, and skipping a property whose type the script engine does not know is expected there; with the raise, any class with such a property can no longer be registered that way. Raising only for explicit RegisterProperty calls (e.g. a flag set while RegisterPublishedProperties runs) keeps the new check without that side effect.

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>
@TetzkatLipHoka TetzkatLipHoka changed the title Raise instead of silently dropping a property with an unresolved type RegisterProperty: opt-in check for properties with an unresolved type Nov 6, 2026
@TetzkatLipHoka

Copy link
Copy Markdown
Author

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 PopupMenu without the Menus import), so those units rely on dropping. I changed the PR: the default behaviour is unchanged, TPSPascalCompiler.StrictPropertyRegistration opts in to the raise for a host's own registrations, RegisterPublishedProperties stays silent, and RegisterPublishedProperty returns False for an unknown type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants