Support assigning Variants and cross-typed interfaces to interface variables#305
Open
TetzkatLipHoka wants to merge 1 commit into
Open
Conversation
…riables Assigning a Variant that holds an interface reference to a script variable of an interface type only worked when the destination was exactly IDispatch; every other interface destination failed with a plain 'Type Mismatch'. Assignments between differently declared interface types blindly copied the reference without ever consulting QueryInterface. SetVariantValue's btInterface branch now: - accepts Variants holding varUnknown/varDispatch values (including by-ref variants) for ANY interface destination, casting via QueryInterface on the destination's GUID; empty/nil Variants assign nil. Destinations declared as IUnknown (or without a GUID) receive the reference as-is, preserving existing behaviour. - performs interface-to-interface assignments of differently declared types via QueryInterface as well; same-GUID (and nil) assignments stay plain reference copies. Failed casts raise a descriptive, script-catchable error that names the destination type (or its GUID when the type is unnamed) instead of the generic type mismatch. Pre-Delphi3 builds keep their previous paths. Note: the companion fix 'Make failing interface/object casts catchable' covers the explicit cast-import path (CastProc); together they make all interface conversion failures catchable with descriptive messages. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Assigning a Variant that holds an interface reference to a script
variable of an interface type only worked when the destination was
exactly IDispatch; every other interface destination failed with a
plain 'Type Mismatch'. Assignments between differently declared
interface types blindly copied the reference without ever consulting
QueryInterface.
SetVariantValue's btInterface branch now:
by-ref variants) for ANY interface destination, casting via
QueryInterface on the destination's GUID; empty/nil Variants assign
nil. Destinations declared as IUnknown (or without a GUID) receive
the reference as-is, preserving existing behaviour.
types via QueryInterface as well; same-GUID (and nil) assignments
stay plain reference copies.
Failed casts raise a descriptive, script-catchable error that names the
destination type (or its GUID when the type is unnamed) instead of the
generic type mismatch. Pre-Delphi3 builds keep their previous paths.
Note: the companion fix 'Make failing interface/object casts catchable'
covers the explicit cast-import path (CastProc); together they make all
interface conversion failures catchable with descriptive messages.
Note: the "failing cast is catchable" check of the included repro additionally needs the catchable-cast-errors PR; the two branches merge cleanly together.
🤖 Generated with Claude Code