From 4de25e9a350018eceba72195c78a240698585a6a Mon Sep 17 00:00:00 2001 From: AlekseyTs Date: Fri, 4 Nov 2016 09:51:13 -0700 Subject: [PATCH] Report use-site errors for types with possibly inaccurate TypeKind value. Fixes #14267. --- .../Portable/Emitter/Model/PEModuleBuilder.cs | 3 +- .../Symbols/Metadata/PE/PENamedTypeSymbol.cs | 21 +++ .../Emit/Attributes/AttributeTests_Tuples.cs | 17 +- .../Test/Emit/CodeGen/CodeGenTupleTest.cs | 35 ++++- .../EditAndContinue/LocalSlotMappingTests.cs | 2 +- .../CSharp/Test/Emit/PDB/PDBTests.cs | 4 +- .../CSharp/Test/Emit/PDB/PDBTupleTests.cs | 10 +- .../Semantic/Semantics/UseSiteErrorTests.cs | 138 ++++++++++++++++ .../SymbolDisplay/SymbolDisplayTests.cs | 2 +- .../Portable/Emit/SymbolTranslator.vb | 3 +- .../Symbols/Metadata/PE/PENamedTypeSymbol.vb | 24 +++ .../Test/Emit/CodeGen/CodeGenTuples.vb | 27 ++++ .../Test/Emit/PDB/PDBTupleTests.vb | 2 +- .../Semantic/Semantics/UseSiteErrorTests.vb | 147 ++++++++++++++++++ .../SymbolDisplay/SymbolDisplayTests.vb | 4 +- .../Test/ExpressionCompiler/TupleTests.cs | 26 ++-- .../Test/ExpressionCompiler/TupleTests.vb | 22 +-- 17 files changed, 441 insertions(+), 46 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs b/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs index c959328def4c1..96608622ed537 100644 --- a/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs +++ b/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs @@ -898,8 +898,7 @@ private void CheckTupleUnderlying(NamedTypeSymbol namedTypeSymbol, SyntaxNode sy // but if it does happen we should make it a failure. // NOTE: declaredBase could be null for interfaces var declaredBase = namedTypeSymbol.BaseTypeNoUseSiteDiagnostics; - if (declaredBase == null || - (declaredBase.SpecialType != SpecialType.System_ValueType && !declaredBase.IsErrorType())) + if (declaredBase == null || declaredBase.SpecialType != SpecialType.System_ValueType) { // Try to decrease noise by not complaining about the same type over and over again. if (_reportedErrorTypesMap.Add(namedTypeSymbol)) diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs index 0e60d59ad56aa..e383c587a3fd4 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs @@ -1918,6 +1918,27 @@ protected virtual DiagnosticInfo GetUseSiteDiagnosticImpl() { diagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BogusType, this); } + else if (TypeKind == TypeKind.Class && SpecialType != SpecialType.System_Enum) + { + TypeSymbol @base = GetDeclaredBaseType(null); + if (@base?.SpecialType == SpecialType.None && @base.ContainingAssembly?.IsMissing == true) + { + var missingType = @base as MissingMetadataTypeSymbol.TopLevel; + if ((object)missingType != null && missingType.Arity == 0) + { + string emittedName = MetadataHelpers.BuildQualifiedName(missingType.NamespaceName, missingType.MetadataName); + switch (SpecialTypes.GetTypeFromMetadataName(emittedName)) + { + case SpecialType.System_Enum: + case SpecialType.System_MulticastDelegate: + case SpecialType.System_ValueType: + // This might be a structure, an enum, or a delegate + diagnostic = missingType.GetUseSiteDiagnostic(); + break; + } + } + } + } } return diagnostic; diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Tuples.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Tuples.cs index 0da938b4e6785..4b6dd9d2b309f 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Tuples.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Tuples.cs @@ -163,7 +163,13 @@ static void Main() comp.VerifyDiagnostics( // (6,11): error CS0518: Predefined type 'System.String' is not defined or imported // D<(int x, int y)> d = o => { }; - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "(int x, int y)").WithArguments("System.String").WithLocation(6, 11) + Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "(int x, int y)").WithArguments("System.String").WithLocation(6, 11), + // (6,11): error CS0012: The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. + // D<(int x, int y)> d = o => { }; + Diagnostic(ErrorCode.ERR_NoTypeDef, "(int x, int y)").WithArguments("System.ValueType", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").WithLocation(6, 11), + // (7,11): error CS0012: The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. + // d((0, 0)); + Diagnostic(ErrorCode.ERR_NoTypeDef, "(0, 0)").WithArguments("System.ValueType", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").WithLocation(7, 11) ); } @@ -193,7 +199,14 @@ class C comp.VerifyDiagnostics( // (4,12): error CS0518: Predefined type 'System.String' is not defined or imported // static (int x, int y) M() => (0, 0); - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "(int x, int y)").WithArguments("System.String").WithLocation(4, 12)); + Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "(int x, int y)").WithArguments("System.String").WithLocation(4, 12), + // (4,12): error CS0012: The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. + // static (int x, int y) M() => (0, 0); + Diagnostic(ErrorCode.ERR_NoTypeDef, "(int x, int y)").WithArguments("System.ValueType", "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a").WithLocation(4, 12), + // (4,34): error CS0012: The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. + // static (int x, int y) M() => (0, 0); + Diagnostic(ErrorCode.ERR_NoTypeDef, "(0, 0)").WithArguments("System.ValueType", "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a").WithLocation(4, 34) + ); } [Fact] diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs index 4d94559d38d2b..80710826bb294 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs @@ -2833,7 +2833,7 @@ static void Main() } "; - var comp = CreateCompilationWithMscorlib(source, references: new[] { ValueTupleRef }); + var comp = CreateCompilationWithMscorlib(source, references: s_valueTupleRefs); comp.VerifyDiagnostics( // (6,37): error CS8125: Tuple member name 'Item10' is only allowed at position 10. // (int Item1, int Item01, int Item10) x = (Item01: 1, Item1: 2, Item10: 3); @@ -2904,7 +2904,7 @@ static void Main() } "; - var comp = CreateCompilationWithMscorlib(source, references: new[] { ValueTupleRef }); + var comp = CreateCompilationWithMscorlib(source, references: s_valueTupleRefs); comp.VerifyDiagnostics( // (6,28): error CS8125: Tuple member name 'Item3' is only allowed at position 3. // (int Item1, string Item3, string Item2, int Item4, int Item5, int Item6, int Item7, string Rest) x = (Item2: "bad", Item4: "bad", Item3: 3, Item4: 4, Item5: 5, Item6: 6, Item7: 7, Rest: "bad"); @@ -2940,7 +2940,7 @@ static void Main() } "; - var comp = CreateCompilationWithMscorlib(source, references: new[] { ValueTupleRef }); + var comp = CreateCompilationWithMscorlib(source, references: s_valueTupleRefs); comp.VerifyDiagnostics( // (6,18): error CS8126: Tuple member name 'CompareTo' is disallowed at any position. // var x = (CompareTo: 2, Create: 3, Deconstruct: 4, Equals: 5, GetHashCode: 6, Rest: 8, ToString: 10); @@ -13936,7 +13936,7 @@ public static void Main() var comp = CreateCompilationWithMscorlib(source3, references: new[] { comp1.ToMetadataReference(), comp2.ToMetadataReference().WithAliases(ImmutableArray.Create("alias1")), - ValueTupleRef }, + SystemRuntimeFacadeRef, ValueTupleRef }, parseOptions: TestOptions.Regular, options: TestOptions.DebugExe); @@ -19738,6 +19738,7 @@ implicit operator AA -- --"); } + [WorkItem(14708, "https://github.com/dotnet/roslyn/issues/14708")] [WorkItem(14709, "https://github.com/dotnet/roslyn/issues/14709")] [Fact] @@ -19902,6 +19903,32 @@ class C2: ClassLibrary1.C1 Assert.Equal("ref (System.Int32, dynamic) ClassLibrary1.C1.Foo.get", b.GetMethod.ToTestDisplayString()); } + [Fact] + [WorkItem(14267, "https://github.com/dotnet/roslyn/issues/14267")] + public void NoSystemRuntimeFacade() + { + var source = @" +class C +{ + static void M() + { + var o = (1, 2); + } +} +"; + + var compilation = CreateCompilationWithMscorlib(source, + references: new[] { ValueTupleRef }); + + Assert.Equal(TypeKind.Class, compilation.GetWellKnownType(WellKnownType.System_ValueTuple_T2).TypeKind); + + compilation.VerifyDiagnostics( + // (6,17): error CS0012: The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. + // var o = (1, 2); + Diagnostic(ErrorCode.ERR_NoTypeDef, "(1, 2)").WithArguments("System.ValueType", "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a").WithLocation(6, 17) + ); + } + [Fact] [WorkItem(14649, "https://github.com/dotnet/roslyn/issues/14649")] public void ParseLongLambda() diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/LocalSlotMappingTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/LocalSlotMappingTests.cs index fd93742a7118a..85e72d1d0a10e 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/LocalSlotMappingTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/LocalSlotMappingTests.cs @@ -1492,7 +1492,7 @@ static void M((dynamic, int) t) var compilation0 = CreateCompilationWithMscorlib( source, options: TestOptions.DebugDll, - references: new[] { SystemCoreRef, CSharpRef, ValueTupleRef }); + references: new[] { SystemCoreRef, CSharpRef, ValueTupleRef, SystemRuntimeFacadeRef }); var compilation1 = compilation0.WithSource(source); var testData0 = new CompilationTestData(); diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs index a72e5c8e32253..fe915af14d7be 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs @@ -407,7 +407,7 @@ static void F() } }"; - var debug = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugWinMD); + var debug = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugWinMD); debug.VerifyPdb( @" @@ -429,7 +429,7 @@ static void F() "); - var release = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.ReleaseWinMD); + var release = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.ReleaseWinMD); release.VerifyPdb( @" diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTupleTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTupleTests.cs index 7837b6d75b65a..25cd0d12289b6 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTupleTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTupleTests.cs @@ -19,7 +19,7 @@ static void F() (int A, int B, (int C, int), int, int, int G, int H, int I) t = (1, 2, (3, 4), 5, 6, 7, 8, 9); } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); comp.VerifyPdb( @" @@ -63,7 +63,7 @@ static void F() const C<(int A, int B)> c = null; } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); comp.VerifyPdb( @" @@ -112,7 +112,7 @@ static void F() } } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); comp.VerifyPdb( @" @@ -176,7 +176,7 @@ static void F() (int \u1234, int, int \u005f\u1200\u005f) \u1200 = (1, 2, 3); } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); comp.VerifyPdb( string.Format(@" @@ -224,7 +224,7 @@ static void F(System.Collections.Generic.IEnumerable<(int a, int b)> ie) } //10,9 } //11,5 }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); comp.VerifyPdb( string.Format(@" diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/UseSiteErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/UseSiteErrorTests.cs index edbeeec17a44e..65b2c54c7be03 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/UseSiteErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/UseSiteErrorTests.cs @@ -2336,5 +2336,143 @@ private static CSharpCompilation CompileWithMissingReference(string source) var failingCompilation = CreateCompilationWithMscorlib(source, new MetadataReference[] { csharpAssemblyReference, ilAssemblyReference }); return failingCompilation; } + + [Fact] + [WorkItem(14267, "https://github.com/dotnet/roslyn/issues/14267")] + public void MissingTypeKindBasisTypes() + { + var source1 = @" +public struct A {} + +public enum B {} + +public class C {} +public delegate void D(); + +public interface I1 {} +"; + var compilation1 = CreateCompilation(source1, options: TestOptions.ReleaseDll, references: new [] { MinCorlibRef }); + compilation1.VerifyEmitDiagnostics(); + + Assert.Equal(TypeKind.Struct, compilation1.GetTypeByMetadataName("A").TypeKind); + Assert.Equal(TypeKind.Enum, compilation1.GetTypeByMetadataName("B").TypeKind); + Assert.Equal(TypeKind.Class, compilation1.GetTypeByMetadataName("C").TypeKind); + Assert.Equal(TypeKind.Delegate, compilation1.GetTypeByMetadataName("D").TypeKind); + Assert.Equal(TypeKind.Interface, compilation1.GetTypeByMetadataName("I1").TypeKind); + + var source2 = @" +interface I2 +{ + I1 M(A a, B b, C c, D d); +} +"; + + var compilation2 = CreateCompilation(source2, options: TestOptions.ReleaseDll, references: new[] { compilation1.EmitToImageReference(), MinCorlibRef }); + + compilation2.VerifyEmitDiagnostics(); + CompileAndVerify(compilation2); + + Assert.Equal(TypeKind.Struct, compilation2.GetTypeByMetadataName("A").TypeKind); + Assert.Equal(TypeKind.Enum, compilation2.GetTypeByMetadataName("B").TypeKind); + Assert.Equal(TypeKind.Class, compilation2.GetTypeByMetadataName("C").TypeKind); + Assert.Equal(TypeKind.Delegate, compilation2.GetTypeByMetadataName("D").TypeKind); + Assert.Equal(TypeKind.Interface, compilation2.GetTypeByMetadataName("I1").TypeKind); + + var compilation3 = CreateCompilation(source2, options: TestOptions.ReleaseDll, references: new[] { compilation1.ToMetadataReference(), MinCorlibRef }); + + compilation3.VerifyEmitDiagnostics(); + CompileAndVerify(compilation3); + + Assert.Equal(TypeKind.Struct, compilation3.GetTypeByMetadataName("A").TypeKind); + Assert.Equal(TypeKind.Enum, compilation3.GetTypeByMetadataName("B").TypeKind); + Assert.Equal(TypeKind.Class, compilation3.GetTypeByMetadataName("C").TypeKind); + Assert.Equal(TypeKind.Delegate, compilation3.GetTypeByMetadataName("D").TypeKind); + Assert.Equal(TypeKind.Interface, compilation3.GetTypeByMetadataName("I1").TypeKind); + + var compilation4 = CreateCompilation(source2, options: TestOptions.ReleaseDll, references: new[] { compilation1.EmitToImageReference() }); + + compilation4.VerifyDiagnostics( + // (4,10): error CS0012: The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2'. + // I1 M(A a, B b, C c, D d); + Diagnostic(ErrorCode.ERR_NoTypeDef, "A").WithArguments("System.ValueType", "mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2").WithLocation(4, 10), + // (4,15): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2'. + // I1 M(A a, B b, C c, D d); + Diagnostic(ErrorCode.ERR_NoTypeDef, "B").WithArguments("System.Enum", "mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2").WithLocation(4, 15), + // (4,25): error CS0012: The type 'MulticastDelegate' is defined in an assembly that is not referenced. You must add a reference to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2'. + // I1 M(A a, B b, C c, D d); + Diagnostic(ErrorCode.ERR_NoTypeDef, "D").WithArguments("System.MulticastDelegate", "mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2").WithLocation(4, 25) + ); + + var a = compilation4.GetTypeByMetadataName("A"); + var b = compilation4.GetTypeByMetadataName("B"); + var c = compilation4.GetTypeByMetadataName("C"); + var d = compilation4.GetTypeByMetadataName("D"); + var i1 = compilation4.GetTypeByMetadataName("I1"); + Assert.Equal(TypeKind.Class, a.TypeKind); + Assert.NotNull(a.GetUseSiteDiagnostic()); + Assert.Equal(TypeKind.Class, b.TypeKind); + Assert.NotNull(b.GetUseSiteDiagnostic()); + Assert.Equal(TypeKind.Class, c.TypeKind); + Assert.Null(c.GetUseSiteDiagnostic()); + Assert.Equal(TypeKind.Class, d.TypeKind); + Assert.NotNull(d.GetUseSiteDiagnostic()); + Assert.Equal(TypeKind.Interface, i1.TypeKind); + Assert.Null(i1.GetUseSiteDiagnostic()); + + var compilation5 = CreateCompilation(source2, options: TestOptions.ReleaseDll, references: new[] { compilation1.ToMetadataReference() }); + + compilation5.VerifyEmitDiagnostics( + // 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) + ); + CompileAndVerify(compilation5); + + Assert.Equal(TypeKind.Struct, compilation5.GetTypeByMetadataName("A").TypeKind); + Assert.Equal(TypeKind.Enum, compilation5.GetTypeByMetadataName("B").TypeKind); + Assert.Equal(TypeKind.Class, compilation5.GetTypeByMetadataName("C").TypeKind); + Assert.Equal(TypeKind.Delegate, compilation5.GetTypeByMetadataName("D").TypeKind); + Assert.Equal(TypeKind.Interface, compilation5.GetTypeByMetadataName("I1").TypeKind); + + var compilation6 = CreateCompilation(source2, options: TestOptions.ReleaseDll, references: new[] { compilation1.EmitToImageReference(), MscorlibRef }); + + compilation6.VerifyDiagnostics( + // (4,10): error CS0012: The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2'. + // I1 M(A a, B b, C c, D d); + Diagnostic(ErrorCode.ERR_NoTypeDef, "A").WithArguments("System.ValueType", "mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2").WithLocation(4, 10), + // (4,15): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2'. + // I1 M(A a, B b, C c, D d); + Diagnostic(ErrorCode.ERR_NoTypeDef, "B").WithArguments("System.Enum", "mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2").WithLocation(4, 15), + // (4,25): error CS0012: The type 'MulticastDelegate' is defined in an assembly that is not referenced. You must add a reference to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2'. + // I1 M(A a, B b, C c, D d); + Diagnostic(ErrorCode.ERR_NoTypeDef, "D").WithArguments("System.MulticastDelegate", "mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2").WithLocation(4, 25) + ); + + a = compilation6.GetTypeByMetadataName("A"); + b = compilation6.GetTypeByMetadataName("B"); + c = compilation6.GetTypeByMetadataName("C"); + d = compilation6.GetTypeByMetadataName("D"); + i1 = compilation6.GetTypeByMetadataName("I1"); + Assert.Equal(TypeKind.Class, a.TypeKind); + Assert.NotNull(a.GetUseSiteDiagnostic()); + Assert.Equal(TypeKind.Class, b.TypeKind); + Assert.NotNull(b.GetUseSiteDiagnostic()); + Assert.Equal(TypeKind.Class, c.TypeKind); + Assert.Null(c.GetUseSiteDiagnostic()); + Assert.Equal(TypeKind.Class, d.TypeKind); + Assert.NotNull(d.GetUseSiteDiagnostic()); + Assert.Equal(TypeKind.Interface, i1.TypeKind); + Assert.Null(i1.GetUseSiteDiagnostic()); + + var compilation7 = CreateCompilation(source2, options: TestOptions.ReleaseDll, references: new[] { compilation1.ToMetadataReference(), MscorlibRef }); + + compilation7.VerifyEmitDiagnostics(); + CompileAndVerify(compilation7); + + Assert.Equal(TypeKind.Struct, compilation7.GetTypeByMetadataName("A").TypeKind); + Assert.Equal(TypeKind.Enum, compilation7.GetTypeByMetadataName("B").TypeKind); + Assert.Equal(TypeKind.Class, compilation7.GetTypeByMetadataName("C").TypeKind); + Assert.Equal(TypeKind.Delegate, compilation7.GetTypeByMetadataName("D").TypeKind); + Assert.Equal(TypeKind.Interface, compilation7.GetTypeByMetadataName("I1").TypeKind); + } } } diff --git a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs index cdfdf6be5a9a2..bf515a1c1d6e1 100644 --- a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs @@ -4703,7 +4703,7 @@ class C genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, memberOptions: SymbolDisplayMemberOptions.IncludeType, miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes); - var comp = CreateCompilationWithMscorlib(text, references: new[] { ValueTupleRef }); + var comp = CreateCompilationWithMscorlib(text, references: new[] { SystemRuntimeFacadeRef, ValueTupleRef }); comp.VerifyDiagnostics(); var symbol = comp.GetMember("C.f"); diff --git a/src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb b/src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb index 64bbf4c0003fd..872571bbf1853 100644 --- a/src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb +++ b/src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb @@ -209,8 +209,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit ' but if it does happen we should make it a failure. ' NOTE: declaredBase could be null for interfaces Dim declaredBase = namedTypeSymbol.BaseTypeNoUseSiteDiagnostics - If declaredBase Is Nothing OrElse - (declaredBase.SpecialType <> SpecialType.System_ValueType AndAlso Not declaredBase.IsErrorType()) Then + If declaredBase Is Nothing OrElse declaredBase.SpecialType <> SpecialType.System_ValueType Then ' Try to decrease noise by not complaining about the same type over and over again. If (_reportedErrorTypesMap.Add(namedTypeSymbol)) Then diagnostics.Add(New VBDiagnostic( diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.vb index 5322697e43ffb..caa2b6320acab 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.vb @@ -1267,6 +1267,30 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Return ErrorFactory.ErrorInfo(ERRID.ERR_UnsupportedType1, Me) End If + Dim typeKind = Me.TypeKind + Dim specialtype = Me.SpecialType + If (typeKind = TypeKind.Class OrElse typeKind = TypeKind.Module) AndAlso + specialtype <> SpecialType.System_Enum AndAlso specialtype <> SpecialType.System_MulticastDelegate Then + Dim base As TypeSymbol = GetDeclaredBase(Nothing) + + If base?.SpecialType = SpecialType.None AndAlso base.ContainingAssembly?.IsMissing Then + Dim missingType = TryCast(base, MissingMetadataTypeSymbol.TopLevel) + + If missingType IsNot Nothing AndAlso missingType.Arity = 0 Then + Dim emittedName As String = MetadataHelpers.BuildQualifiedName(missingType.NamespaceName, missingType.MetadataName) + + Select Case SpecialTypes.GetTypeFromMetadataName(emittedName) + Case SpecialType.System_Enum, + SpecialType.System_Delegate, + SpecialType.System_MulticastDelegate, + SpecialType.System_ValueType + ' This might be a structure, an enum, or a delegate + Return missingType.GetUseSiteErrorInfo() + End Select + End If + End If + End If + ' Verify type parameters for containing types ' match those on the containing types. If Not MatchesContainingTypeParameters() Then diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb index a7a9793e0cf97..dbf434e681366 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb @@ -17198,6 +17198,33 @@ BC41009: The tuple element name 'd' is ignored because a different name is speci End Sub + + + Public Sub NoSystemRuntimeFacade() + Dim comp = CreateCompilationWithMscorlibAndVBRuntime( + + +, additionalRefs:={ValueTupleRef}) + + Assert.Equal(TypeKind.Class, comp.GetWellKnownType(WellKnownType.System_ValueTuple_T2).TypeKind) + + comp.AssertTheseDiagnostics( + +BC30652: Reference required to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' containing the type 'ValueType'. Add one to your project. + Dim o = (1, 2) + ~~~~~~ +) + End Sub + Public Sub UserDefinedConversionsAndNameMismatch_01() diff --git a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTupleTests.vb b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTupleTests.vb index b37a1369939a5..3c2dee5be373d 100644 --- a/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTupleTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/PDB/PDBTupleTests.vb @@ -19,7 +19,7 @@ Class C End Class ]]> - Dim comp = CreateCompilationWithMscorlib(source, references:={ValueTupleRef}, options:=TestOptions.DebugDll) + Dim comp = CreateCompilationWithMscorlib(source, references:={ValueTupleRef, SystemRuntimeFacadeRef}, options:=TestOptions.DebugDll) comp.VerifyPdb("C.F", diff --git a/src/Compilers/VisualBasic/Test/Semantic/Semantics/UseSiteErrorTests.vb b/src/Compilers/VisualBasic/Test/Semantic/Semantics/UseSiteErrorTests.vb index 737448d4c847c..05bad3016fabc 100644 --- a/src/Compilers/VisualBasic/Test/Semantic/Semantics/UseSiteErrorTests.vb +++ b/src/Compilers/VisualBasic/Test/Semantic/Semantics/UseSiteErrorTests.vb @@ -1,6 +1,7 @@ ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports System.Xml.Linq +Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.VisualBasic.Symbols Imports Microsoft.CodeAnalysis.VisualBasic.Syntax @@ -528,5 +529,151 @@ BC30002: Type 'System.Int32' is not defined. Return failingCompilation End Function + + + Public Sub MissingTypeKindBasisTypes() + Dim source1 = + + +Public Structure A +End Structure + +Public Enum B + x +End Enum + +Public Class C +End Class + +Public Delegate Sub D() + +Public Interface I1 +End Interface + + + + Dim compilation1 = CreateCompilationWithReferences(source1, options:=TestOptions.ReleaseDll, references:={MinCorlibRef}) + compilation1.VerifyEmitDiagnostics() + + Assert.Equal(TypeKind.Struct, compilation1.GetTypeByMetadataName("A").TypeKind) + Assert.Equal(TypeKind.Enum, compilation1.GetTypeByMetadataName("B").TypeKind) + Assert.Equal(TypeKind.Class, compilation1.GetTypeByMetadataName("C").TypeKind) + Assert.Equal(TypeKind.Delegate, compilation1.GetTypeByMetadataName("D").TypeKind) + Assert.Equal(TypeKind.Interface, compilation1.GetTypeByMetadataName("I1").TypeKind) + + Dim source2 = + + +Interface I2 + Function M(a As A, b As B, c As C, d As D) As I1 +End Interface + + + + Dim compilation2 = CreateCompilationWithReferences(source2, options:=TestOptions.ReleaseDll, references:={compilation1.EmitToImageReference(), MinCorlibRef}) + + compilation2.VerifyEmitDiagnostics() + CompileAndVerify(compilation2) + + Assert.Equal(TypeKind.Struct, compilation2.GetTypeByMetadataName("A").TypeKind) + Assert.Equal(TypeKind.Enum, compilation2.GetTypeByMetadataName("B").TypeKind) + Assert.Equal(TypeKind.Class, compilation2.GetTypeByMetadataName("C").TypeKind) + Assert.Equal(TypeKind.Delegate, compilation2.GetTypeByMetadataName("D").TypeKind) + Assert.Equal(TypeKind.Interface, compilation2.GetTypeByMetadataName("I1").TypeKind) + + Dim compilation3 = CreateCompilationWithReferences(source2, options:=TestOptions.ReleaseDll, references:={compilation1.ToMetadataReference(), MinCorlibRef}) + + compilation3.VerifyEmitDiagnostics() + CompileAndVerify(compilation3) + + Assert.Equal(TypeKind.Struct, compilation3.GetTypeByMetadataName("A").TypeKind) + Assert.Equal(TypeKind.Enum, compilation3.GetTypeByMetadataName("B").TypeKind) + Assert.Equal(TypeKind.Class, compilation3.GetTypeByMetadataName("C").TypeKind) + Assert.Equal(TypeKind.Delegate, compilation3.GetTypeByMetadataName("D").TypeKind) + Assert.Equal(TypeKind.Interface, compilation3.GetTypeByMetadataName("I1").TypeKind) + + Dim compilation4 = CreateCompilationWithReferences(source2, options:=TestOptions.ReleaseDll, references:={compilation1.EmitToImageReference()}) + + compilation4.AssertTheseDiagnostics( +BC30652: Reference required to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2' containing the type 'ValueType'. Add one to your project. + Function M(a As A, b As B, c As C, d As D) As I1 + ~ +BC30652: Reference required to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2' containing the type '[Enum]'. Add one to your project. + Function M(a As A, b As B, c As C, d As D) As I1 + ~ +BC30652: Reference required to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2' containing the type 'MulticastDelegate'. Add one to your project. + Function M(a As A, b As B, c As C, d As D) As I1 + ~ + ) + + Dim a = compilation4.GetTypeByMetadataName("A") + Dim b = compilation4.GetTypeByMetadataName("B") + Dim c = compilation4.GetTypeByMetadataName("C") + Dim d = compilation4.GetTypeByMetadataName("D") + Dim i1 = compilation4.GetTypeByMetadataName("I1") + Assert.Equal(TypeKind.Class, a.TypeKind) + Assert.NotNull(a.GetUseSiteErrorInfo()) + Assert.Equal(TypeKind.Class, b.TypeKind) + Assert.NotNull(b.GetUseSiteErrorInfo()) + Assert.Equal(TypeKind.Class, c.TypeKind) + Assert.Null(c.GetUseSiteErrorInfo()) + Assert.Equal(TypeKind.Class, d.TypeKind) + Assert.NotNull(d.GetUseSiteErrorInfo()) + Assert.Equal(TypeKind.Interface, i1.TypeKind) + Assert.Null(i1.GetUseSiteErrorInfo()) + + Dim compilation5 = CreateCompilationWithReferences(source2, options:=TestOptions.ReleaseDll, references:={compilation1.ToMetadataReference()}) + + compilation5.VerifyEmitDiagnostics() + CompileAndVerify(compilation5) + + Assert.Equal(TypeKind.Struct, compilation5.GetTypeByMetadataName("A").TypeKind) + Assert.Equal(TypeKind.Enum, compilation5.GetTypeByMetadataName("B").TypeKind) + Assert.Equal(TypeKind.Class, compilation5.GetTypeByMetadataName("C").TypeKind) + Assert.Equal(TypeKind.Delegate, compilation5.GetTypeByMetadataName("D").TypeKind) + Assert.Equal(TypeKind.Interface, compilation5.GetTypeByMetadataName("I1").TypeKind) + + Dim compilation6 = CreateCompilationWithReferences(source2, options:=TestOptions.ReleaseDll, references:={compilation1.EmitToImageReference(), MscorlibRef}) + + compilation6.AssertTheseDiagnostics( +BC30652: Reference required to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2' containing the type 'ValueType'. Add one to your project. + Function M(a As A, b As B, c As C, d As D) As I1 + ~ +BC30652: Reference required to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2' containing the type '[Enum]'. Add one to your project. + Function M(a As A, b As B, c As C, d As D) As I1 + ~ +BC30652: Reference required to assembly 'mincorlib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ce65828c82a341f2' containing the type 'MulticastDelegate'. Add one to your project. + Function M(a As A, b As B, c As C, d As D) As I1 + ~ + ) + + a = compilation6.GetTypeByMetadataName("A") + b = compilation6.GetTypeByMetadataName("B") + c = compilation6.GetTypeByMetadataName("C") + d = compilation6.GetTypeByMetadataName("D") + i1 = compilation6.GetTypeByMetadataName("I1") + Assert.Equal(TypeKind.Class, a.TypeKind) + Assert.NotNull(a.GetUseSiteErrorInfo()) + Assert.Equal(TypeKind.Class, b.TypeKind) + Assert.NotNull(b.GetUseSiteErrorInfo()) + Assert.Equal(TypeKind.Class, c.TypeKind) + Assert.Null(c.GetUseSiteErrorInfo()) + Assert.Equal(TypeKind.Class, d.TypeKind) + Assert.NotNull(d.GetUseSiteErrorInfo()) + Assert.Equal(TypeKind.Interface, i1.TypeKind) + Assert.Null(i1.GetUseSiteErrorInfo()) + + Dim compilation7 = CreateCompilationWithReferences(source2, options:=TestOptions.ReleaseDll, references:={compilation1.ToMetadataReference(), MscorlibRef}) + + compilation7.VerifyEmitDiagnostics() + CompileAndVerify(compilation7) + + Assert.Equal(TypeKind.Struct, compilation7.GetTypeByMetadataName("A").TypeKind) + Assert.Equal(TypeKind.Enum, compilation7.GetTypeByMetadataName("B").TypeKind) + Assert.Equal(TypeKind.Class, compilation7.GetTypeByMetadataName("C").TypeKind) + Assert.Equal(TypeKind.Delegate, compilation7.GetTypeByMetadataName("D").TypeKind) + Assert.Equal(TypeKind.Interface, compilation7.GetTypeByMetadataName("I1").TypeKind) + End Sub + End Class End Namespace diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/SymbolDisplayTests.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/SymbolDisplayTests.vb index 6209029781ba3..b858188492c82 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/SymbolDisplayTests.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolDisplay/SymbolDisplayTests.vb @@ -4818,7 +4818,7 @@ End Class" genericsOptions:=SymbolDisplayGenericsOptions.IncludeTypeParameters, memberOptions:=SymbolDisplayMemberOptions.IncludeType, miscellaneousOptions:=SymbolDisplayMiscellaneousOptions.UseSpecialTypes) - Dim comp = CompilationUtils.CreateCompilationWithMscorlib(source, references:={ValueTupleRef}) + Dim comp = CompilationUtils.CreateCompilationWithMscorlib(source, references:={SystemRuntimeFacadeRef, ValueTupleRef}) comp.VerifyDiagnostics() Dim symbol = comp.GetMember("C.f") @@ -4856,7 +4856,7 @@ End Class" Dim format = New SymbolDisplayFormat( memberOptions:=SymbolDisplayMemberOptions.IncludeType, miscellaneousOptions:=SymbolDisplayMiscellaneousOptions.UseSpecialTypes) - Dim comp = CreateCSharpCompilation(GetUniqueName(), source, referencedAssemblies:={MscorlibRef, ValueTupleRef}) + Dim comp = CreateCSharpCompilation(GetUniqueName(), source, referencedAssemblies:={MscorlibRef, SystemRuntimeFacadeRef, ValueTupleRef}) comp.VerifyDiagnostics() Dim type = comp.GlobalNamespace.GetTypeMembers("C").Single() Verify( diff --git a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/TupleTests.cs b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/TupleTests.cs index df36b69aa4128..8ff61b913e220 100644 --- a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/TupleTests.cs +++ b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/TupleTests.cs @@ -30,8 +30,8 @@ static void M() (int, int) o; } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); - WithRuntimeInstance(comp, runtime => + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); + WithRuntimeInstance(comp, new[] { ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef }, runtime => { var context = CreateMethodContext(runtime, "C.M"); var testData = new CompilationTestData(); @@ -124,8 +124,8 @@ static void M() (int A\u1234, int \u1234B) o = (1, 2); } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); - WithRuntimeInstance(comp, runtime => + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); + WithRuntimeInstance(comp, new[] { ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef }, runtime => { var context = CreateMethodContext(runtime, "C.M"); var testData = new CompilationTestData(); @@ -172,8 +172,8 @@ static void M() const A<(int, int A)>.B<(object B, object)>[] c = null; } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); - WithRuntimeInstance(comp, runtime => + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); + WithRuntimeInstance(comp, new[] { ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef }, runtime => { var context = CreateMethodContext(runtime, "C.M"); var testData = new CompilationTestData(); @@ -215,7 +215,7 @@ static void M() var x = (1, 2, 3, 4, 5, 6, 7, 8); } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); + var comp = CreateCompilationWithMscorlib(source, new[] { SystemRuntimeFacadeRef, ValueTupleRef }, options: TestOptions.DebugDll); WithRuntimeInstance(comp, new[] { MscorlibRef, SystemCoreRef, SystemRuntimeFacadeRef, ValueTupleRef }, runtime => { var context = CreateMethodContext(runtime, "C.M"); @@ -249,7 +249,7 @@ static void M() var x = (1, 2, Three: 3, Four: 4, 5, 6, 7, Eight: 8); } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); + var comp = CreateCompilationWithMscorlib(source, new[] { SystemRuntimeFacadeRef, ValueTupleRef }, options: TestOptions.DebugDll); WithRuntimeInstance(comp, new[] { MscorlibRef, SystemCoreRef, SystemRuntimeFacadeRef, ValueTupleRef }, runtime => { var context = CreateMethodContext(runtime, "C.M"); @@ -284,8 +284,8 @@ static void M() var x = (1, 2); } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); - WithRuntimeInstance(comp, runtime => + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); + WithRuntimeInstance(comp, new[] { ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef }, runtime => { var context = CreateMethodContext(runtime, "C.M"); var testData = new CompilationTestData(); @@ -350,8 +350,8 @@ static void M() { } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); - WithRuntimeInstance(comp, runtime => + var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); + WithRuntimeInstance(comp, new[] { ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef }, runtime => { var context = CreateMethodContext( runtime, @@ -415,7 +415,7 @@ static void M() { } }"; - var comp = CreateCompilationWithMscorlib(source, new[] { ValueTupleRef }, options: TestOptions.DebugDll); + var comp = CreateCompilationWithMscorlib(source, new[] { SystemRuntimeFacadeRef, ValueTupleRef }, options: TestOptions.DebugDll); WithRuntimeInstance(comp, new[] { MscorlibRef, SystemCoreRef, SystemRuntimeFacadeRef, ValueTupleRef }, runtime => { var context = CreateMethodContext(runtime, "C.M"); diff --git a/src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/TupleTests.vb b/src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/TupleTests.vb index d85f2d02da713..b0ef3623559c9 100644 --- a/src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/TupleTests.vb +++ b/src/ExpressionEvaluator/VisualBasic/Test/ExpressionCompiler/TupleTests.vb @@ -26,8 +26,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator.UnitTests Dim o As (Integer, Integer) End Sub End Class" - Dim comp = CreateCompilationWithMscorlib({source}, references:={ValueTupleRef}, options:=TestOptions.DebugDll) - WithRuntimeInstance(comp, + Dim comp = CreateCompilationWithMscorlib({source}, references:={ValueTupleRef, SystemRuntimeFacadeRef}, options:=TestOptions.DebugDll) + WithRuntimeInstance(comp, {MscorlibRef, ValueTupleRef, SystemRuntimeFacadeRef}, Sub(runtime) Dim context = CreateMethodContext(runtime, "C.M") Dim errorMessage As String = Nothing @@ -125,8 +125,8 @@ End Class" (int A, int B) o = (1, 2); } }" - Dim comp = CreateCSharpCompilation(source, referencedAssemblies:={MscorlibRef, ValueTupleRef}) - WithRuntimeInstance(comp, + Dim comp = CreateCSharpCompilation(source, referencedAssemblies:={MscorlibRef, ValueTupleRef, SystemRuntimeFacadeRef}) + WithRuntimeInstance(comp, {MscorlibRef, ValueTupleRef, SystemRuntimeFacadeRef}, Sub(runtime) Dim context = CreateMethodContext(runtime, "C.M") Dim testData = New CompilationTestData() @@ -173,8 +173,8 @@ class C const A<(int, int A)>.B<(object B, object)>[] c = null; } }" - Dim comp = CreateCSharpCompilation(source, referencedAssemblies:={MscorlibRef, ValueTupleRef}) - WithRuntimeInstance(comp, + Dim comp = CreateCSharpCompilation(source, referencedAssemblies:={MscorlibRef, ValueTupleRef, SystemRuntimeFacadeRef}) + WithRuntimeInstance(comp, {MscorlibRef, ValueTupleRef, SystemRuntimeFacadeRef}, Sub(runtime) Dim context = CreateMethodContext(runtime, "C.M") Dim testData = New CompilationTestData() @@ -213,7 +213,7 @@ class C Dim x = (1, 2, 3, 4, 5, 6, 7, 8) End Sub End Class" - Dim comp = CreateCompilationWithMscorlib({source}, references:={ValueTupleRef}, options:=TestOptions.DebugDll) + Dim comp = CreateCompilationWithMscorlib({source}, references:={SystemRuntimeFacadeRef, ValueTupleRef}, options:=TestOptions.DebugDll) WithRuntimeInstance(comp, {MscorlibRef, SystemCoreRef, SystemRuntimeFacadeRef, ValueTupleRef}, Sub(runtime) @@ -250,7 +250,7 @@ End Class" Dim x = (1, 2, Three:=3, Four:=4, 5, 6, 7, Eight:=8) End Sub End Class" - Dim comp = CreateCompilationWithMscorlib({source}, references:={ValueTupleRef}, options:=TestOptions.DebugDll) + Dim comp = CreateCompilationWithMscorlib({source}, references:={SystemRuntimeFacadeRef, ValueTupleRef}, options:=TestOptions.DebugDll) WithRuntimeInstance(comp, {MscorlibRef, SystemCoreRef, SystemRuntimeFacadeRef, ValueTupleRef}, Sub(runtime) @@ -345,8 +345,8 @@ End Class" Shared Sub M() End Sub End Class" - Dim comp = CreateCompilationWithMscorlib({source}, references:={ValueTupleRef}, options:=TestOptions.DebugDll) - WithRuntimeInstance(comp, + Dim comp = CreateCompilationWithMscorlib({source}, references:={ValueTupleRef, SystemRuntimeFacadeRef}, options:=TestOptions.DebugDll) + WithRuntimeInstance(comp, {MscorlibRef, ValueTupleRef, SystemRuntimeFacadeRef}, Sub(runtime) Dim context = CreateMethodContext(runtime, "C.M") Dim locals = ArrayBuilder(Of LocalAndMethod).GetInstance() @@ -404,7 +404,7 @@ End Class" Shared Sub M() End Sub End Class" - Dim comp = CreateCompilationWithMscorlib({source}, references:={ValueTupleRef}, options:=TestOptions.DebugDll) + Dim comp = CreateCompilationWithMscorlib({source}, references:={SystemRuntimeFacadeRef, ValueTupleRef}, options:=TestOptions.DebugDll) WithRuntimeInstance(comp, {MscorlibRef, SystemCoreRef, SystemRuntimeFacadeRef, ValueTupleRef}, Sub(runtime)