Skip to content

Conversation

@marinasundstrom
Copy link
Owner

Motivation

  • Prevent elision of conversions that should call user-defined or extension op_Implicit when targeting nullable reference unions.
  • The compiler previously returned the original expression for Nullable<T> (reference underlying) too broadly, which suppressed emitted conversion calls.
  • This led to missing/incorrect IL for conversions like the implicit operator in OptionExtensions<T> and runtime failures when the conversion was expected to run.

Description

  • Tighten the guard in BlockBinder.ApplyConversion so the early-return for NullableTypeSymbol only occurs when conversion.IsReference and the expression type exactly equals the nullable underlying type using SymbolEqualityComparer.Default.Equals.
  • This ensures user-defined and extension conversion operators (including op_Implicit) are considered and emitted for nullable reference targets instead of being elided.
  • The change is implemented in src/Raven.CodeAnalysis/Binder/BlockBinder.cs by refining the if (targetType is NullableTypeSymbol ...) condition.

Testing

  • Ran the code generation steps (NodeGenerator, BoundNodeGenerator, DiagnosticsGenerator) before building as required by repository guidelines.
  • Built the solution with dotnet build --property WarningLevel=0, which completed successfully.
  • Ran dotnet test test/Raven.CodeAnalysis.Tests /property:WarningLevel=0 -v minimal, which exercised the test suite but encountered many preexisting and unrelated failures; tests did not all pass.
  • Manual verification: inspected emitted IL/behavior for the reported conversion scenario and adjusted the binding logic to allow conversion emission (build verified the change introduced no compilation errors).

Codex Task

@marinasundstrom marinasundstrom merged commit 75206da into main Dec 28, 2025
@marinasundstrom marinasundstrom deleted the codex/fix-access-violation-in-option-conversion branch December 28, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants