Skip to content

Implicit conversion method prioritized over type declaration when using "Go to definition" on invalid constructor #73498

@Rekkonnect

Description

@Rekkonnect

Version Used

VS 2022 Version 17.9.7
Roslyn 4.9.0 (a98c90d)

Project info
C# 12.0
.NET 8.0

Steps to Reproduce

Consider the following scenario:

Given those types:

public abstract class BaseThing;
public sealed class DerivedThing : BaseThing;

public struct Convertible
{
    public static implicit operator Convertible(BaseThing thing) => new();
}

Assume we construct a DerivedThing instance with a constructor that does not exist, causing a compiler error:

void UseConvertible(Convertible convertible) { }

void CreateUseConvertible()
{
    UseConvertible(new DerivedThing(1, 2));
}

Attempt to go to the definition of DerivedThing (F12 or Ctrl+click in VS).

Expected Behavior

We are navigated to the DerivedThing declaration.

Actual Behavior

We are navigated to the implicit operator Convertible(BaseThing) declaration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type

    Projects

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions