No compile-time error when static abstract member accessed on type parameter whose resolved type has no concrete implementation for said member #17139
Labels
Area-Compiler-Checking
Type checking, attributes and all aspects of logic checking
Bug
Impact-Low
(Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone
There is no compile-time error when:
A
System.Runtime.AmbiguousImplementationException
is raised at runtime instead. This is raised even when the interface in question has only one static abstract member (or member of any kind).Repro steps
net8.0
net9.0
Expected behavior
Resolution of the type variable should fail at compile-time in the absence of further type information when the type variable has a constraint involving static abstract members — although ideally it would only fail when an
abstract
(as opposed tovirtual
) member was actually being accessed, which is not visible through a constraint like'T & #IFace
alone.Actual behavior
A type variable like
'T & #IFace
resolves to the interface typeIFace
itself, and aSystem.Runtime.AmbiguousImplementationException
is raised at runtime.Known workarounds
Always manually ensure that all type variables are resolved to types with concrete implementations for all static abstract methods that are invoked on them.
Related information
.NET 8/9 preview.
This problem is similar in spirit to #14012, #16299, etc., although it might be a bit trickier to fix.
The text was updated successfully, but these errors were encountered: