Skip to content

Commit

Permalink
Add overload resolution of constructor with new() and use-site diagno…
Browse files Browse the repository at this point in the history
…stic
  • Loading branch information
jcouv committed Apr 20, 2020
1 parent c241af8 commit 61ebdde
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4210,6 +4210,47 @@ public void M2(C c)
);
}

[Fact]
public void TestInConstructorOverloadWithUseSiteError()
{
var missing = @"public class Missing { }";
var missingComp = CreateCompilation(missing, assemblyName: "missing");

var lib = @"
public class C
{
public C(Missing m) => throw null;
public C(D d) => throw null;
}
public class D { }
";
var libComp = CreateCompilation(lib, references: new[] { missingComp.EmitToImageReference() });

var source = @"
class D
{
public void M2(C c)
{
new C(new());
new C(default);
new C(null);
}
}
";
var comp = CreateCompilation(source, references: new[] { libComp.EmitToImageReference() });
comp.VerifyDiagnostics(
// (6,13): error CS0012: The type 'Missing' is defined in an assembly that is not referenced. You must add a reference to assembly 'missing, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
// new C(new());
Diagnostic(ErrorCode.ERR_NoTypeDef, "C").WithArguments("Missing", "missing, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(6, 13),
// (7,13): error CS0012: The type 'Missing' is defined in an assembly that is not referenced. You must add a reference to assembly 'missing, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
// new C(default);
Diagnostic(ErrorCode.ERR_NoTypeDef, "C").WithArguments("Missing", "missing, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(7, 13),
// (8,13): error CS0012: The type 'Missing' is defined in an assembly that is not referenced. You must add a reference to assembly 'missing, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
// new C(null);
Diagnostic(ErrorCode.ERR_NoTypeDef, "C").WithArguments("Missing", "missing, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").WithLocation(8, 13)
);
}

[Fact]
public void UseSiteWarning()
{
Expand Down

0 comments on commit 61ebdde

Please sign in to comment.