Skip to content

Handle variant conversions more accurately #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Cirras
Copy link
Collaborator

@Cirras Cirras commented May 23, 2025

This one was a real mess.

The initial implementation of variant conversions for invocation resolution was based on the FPC is_better_candidate_single_variant routine because their documentation indicated it was reverse-engineered from Delphi's behavior. Unfortunately, it was inaccurate in many ways.

Some interesting problems in the previous implementation:

  • Comparisons of integer types were based on type identity, while Delphi bases these comparisons on signedness and value range.
  • All real types (as well as Currency and Comp) were preferred over Extended, while Delphi always prefers it over other real types (plus Currency and Comp, but only when theExtended type is larger).
  • Currency and Comp didn't conflict with Single or Extended, while in Delphi they will always conflict with real types of the same size or smaller.
  • Character types (WideChar, AnsiChar) parameters were considered valid targets for variant conversions, while in Delphi they are not.
  • Mixing-and-matching candidates between string, integer, boolean, and real types was allowed, while in Delphi such cases are ambiguous.

@Cirras Cirras requested a review from fourls May 23, 2025 06:46
@Cirras
Copy link
Collaborator Author

Cirras commented May 23, 2025

Oops. Repeated word in the commit message.

... FPC routine
is_better_candidate_single_variant routine ...

@Cirras Cirras force-pushed the variants_are_deeply_upsetting branch from feee515 to fdffacf Compare May 26, 2025 01:59
This one was a real mess.

The initial implementation of variant conversions for invocation
resolution was based on the FPC `is_better_candidate_single_variant`
routine because their documentation indicated it was reverse-engineered
from Delphi's behavior. Unfortunately, it was inaccurate in many ways.

Some interesting problems in the previous implementation:
- Comparisons of integer types were based on type identity, while Delphi
  bases these comparisons on signedness and value range.
- All real types (as well as `Currency` and `Comp`) were preferred over
  `Extended`, while Delphi always prefers it over other real types (plus
  `Currency` and `Comp`, but only when the`Extended` type is larger).
- `Currency` and `Comp` didn't conflict with `Single` or `Extended`,
  while in Delphi they will always conflict with real types of the same
  size or smaller.
- Character types (`WideChar`, `AnsiChar`) parameters were considered
  valid targets for variant conversions, while in Delphi they are not.
- Mixing-and-matching candidates between string, integer, boolean, and
  real types was allowed, while in Delphi such cases are ambiguous.
@Cirras Cirras force-pushed the variants_are_deeply_upsetting branch from fdffacf to 6996d20 Compare May 26, 2025 02:09
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.

1 participant