提交 242bd269 编写于 作者: A AlekseyTs

IsDefinedOrImplementedInSourceTree – when called for an implicitly declared...

IsDefinedOrImplementedInSourceTree – when called for an implicitly declared instance constructor, return the answer for the containing type. This ensures that an error about missing parameter-less base constructor is returned for syntax tree containing declaration of a derived type. (changeset 1378066)
上级 5c65d368
......@@ -2034,6 +2034,12 @@ private static bool IsDefinedOrImplementedInSourceTree(Symbol symbol, SyntaxTree
}
}
if (symbol.Kind == SymbolKind.Method && symbol.IsImplicitlyDeclared && ((MethodSymbol)symbol).MethodKind == MethodKind.Constructor)
{
// Include implicitly declared constructor if containing type is included
return IsDefinedOrImplementedInSourceTree(symbol.ContainingType, tree, span);
}
return false;
}
......
......@@ -14856,7 +14856,7 @@ static void Main()
);
}
[Fact]
[Fact, WorkItem(999399, "DevDiv")]
public void CS1729ERR_BadCtorArgCount()
{
var text = @"
......@@ -14888,7 +14888,9 @@ public Child2(int k)
{
}
}";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
var compilation = CreateCompilationWithMscorlib(text);
DiagnosticDescription[] expected = {
// (21,14): error CS7036: There is no argument given that corresponds to the required formal parameter 'i' of 'Parent.Parent(int, int)'
// public class Child : Parent { } // CS1729
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Child").WithArguments("i", "Parent.Parent(int, int)").WithLocation(21, 14),
......@@ -14900,7 +14902,12 @@ public Child2(int k)
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "Test").WithArguments("Test", "1").WithLocation(7, 26),
// (9,37): error CS7036: There is no argument given that corresponds to the required formal parameter 'j' of 'Parent.Parent(int, int)'
// Parent exampleParent1 = new Parent(10); // CS1729
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Parent").WithArguments("j", "Parent.Parent(int, int)").WithLocation(9, 37));
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "Parent").WithArguments("j", "Parent.Parent(int, int)").WithLocation(9, 37)
};
compilation.VerifyDiagnostics(expected);
compilation.GetDiagnosticsForSyntaxTree(CompilationStage.Compile, compilation.SyntaxTrees.Single(), null, true).Verify(expected);
}
[WorkItem(539631, "DevDiv")]
......
......@@ -120,6 +120,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End If
End If
If symbol.Kind = SymbolKind.Method AndAlso symbol.IsImplicitlyDeclared AndAlso
DirectCast(symbol, MethodSymbol).MethodKind = MethodKind.Constructor Then
' Include implicitly declared constructor if containing type is included
Return IsDefinedOrImplementedInSourceTree(symbol.ContainingType, tree, span)
End If
Return False
End Function
......
......@@ -5492,7 +5492,7 @@ BC30375: 'New' cannot be used on an interface.
End Sub
<Fact()>
<Fact(), WorkItem(999399, "DevDiv")>
Public Sub BC30387ERR_NoConstructorOnBase2()
Dim compilation = CompilationUtils.CreateCompilationWithMscorlibAndVBRuntime(
<compilation name="NoConstructorOnBase2">
......@@ -5508,12 +5508,17 @@ BC30375: 'New' cannot be used on an interface.
End Module
</file>
</compilation>)
CompilationUtils.AssertTheseDiagnostics(compilation,
Dim expected =
<expected>
BC30387: Class 'M1.c1' must declare a 'Sub New' because its base class 'M1.Base' does not have an accessible 'Sub New' that can be called with no arguments.
Class c1
~~
</expected>)
</expected>
CompilationUtils.AssertTheseDiagnostics(compilation, expected)
CompilationUtils.AssertTheseDiagnostics(compilation.GetDiagnosticsForTree(CompilationStage.Compile, compilation.SyntaxTrees.Single(), Nothing, True), expected)
End Sub
<Fact()>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册