提交 de4866d3 编写于 作者: N Neal Gafter

Rename WellKnownMembers

Add test for missing exceptions.
上级 1c99242c
......@@ -91,9 +91,9 @@ private BoundExpression LowerSwitchExpression(BoundSwitchExpression node)
var thrownExpression =
(optionalSavedInput != null &&
implicitConversionExists(optionalSavedInput, objectType) &&
_factory.WellKnownMember(WellKnownMember.System_MatchFailureException__ctor1, isOptional: true) is MethodSymbol newMatchFailureException1)
_factory.WellKnownMember(WellKnownMember.System_MatchFailureException__ctorObject, isOptional: true) is MethodSymbol newMatchFailureException1)
? _factory.New(newMatchFailureException1, _factory.Convert(objectType, optionalSavedInput)) :
(_factory.WellKnownMember(WellKnownMember.System_MatchFailureException__ctor0, isOptional: true) is MethodSymbol newMatchFailureException0)
(_factory.WellKnownMember(WellKnownMember.System_MatchFailureException__ctor, isOptional: true) is MethodSymbol newMatchFailureException0)
? _factory.New(newMatchFailureException0) :
_factory.New(_factory.WellKnownMethod(WellKnownMember.System_InvalidOperationException__ctor));
result.Add(_factory.Throw(thrownExpression));
......
......@@ -1969,5 +1969,37 @@ .maxstack 1
IL_0016: ret
}");
}
[Fact]
public void MissingExceptions_01()
{
var source = @"namespace System {
public class Object { }
public abstract class ValueType { }
public struct Void { }
public struct Boolean { }
public struct Int32 { }
}
static class C {
public static bool M(int i) => i switch { 1 => true };
}
";
var compilation = CreateEmptyCompilation(source, options: TestOptions.ReleaseDll);
compilation.GetDiagnostics().Verify(
// (9,38): warning CS8509: The switch expression does not handle all possible inputs (it is not exhaustive).
// public static bool M(int i) => i switch { 1 => true };
Diagnostic(ErrorCode.WRN_SwitchExpressionNotExhaustive, "switch").WithLocation(9, 38)
);
compilation.GetEmitDiagnostics().Verify(
// warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options.
Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1),
// (9,36): error CS0656: Missing compiler required member 'System.InvalidOperationException..ctor'
// public static bool M(int i) => i switch { 1 => true };
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "i switch { 1 => true }").WithArguments("System.InvalidOperationException", ".ctor").WithLocation(9, 36),
// (9,38): warning CS8509: The switch expression does not handle all possible inputs (it is not exhaustive).
// public static bool M(int i) => i switch { 1 => true };
Diagnostic(ErrorCode.WRN_SwitchExpressionNotExhaustive, "switch").WithLocation(9, 38)
);
}
}
}
......@@ -483,8 +483,8 @@ internal enum WellKnownMember
System_Runtime_CompilerServices_ITuple__get_Length,
System_InvalidOperationException__ctor,
System_MatchFailureException__ctor0,
System_MatchFailureException__ctor1,
System_MatchFailureException__ctor,
System_MatchFailureException__ctorObject,
Count
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册