Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static void Main()

VerifyFieldSymbol(comp.GetMember<FieldSymbol>("S.F"), "ref T S<T>.F", RefKind.Ref, new string[0]);

comp = CreateEmptyCompilation(sourceB, references: new[] { refA, mscorlibRefWithRefFields }, parseOptions: TestOptions.Regular11);
comp = CreateEmptyCompilation(sourceB, references: new[] { refA, mscorlibRefWithRefFields }, parseOptions: TestOptions.Regular11, options: TestOptions.ReleaseExe);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"2
2
Expand Down Expand Up @@ -311,7 +311,7 @@ static void Main()

VerifyFieldSymbol(comp.GetMember<FieldSymbol>("S.F"), "ref readonly T S<T>.F", RefKind.RefReadOnly, new string[0]);

comp = CreateEmptyCompilation(sourceB, references: new[] { refA, mscorlibRefWithRefFields }, parseOptions: TestOptions.Regular11);
comp = CreateEmptyCompilation(sourceB, references: new[] { refA, mscorlibRefWithRefFields }, parseOptions: TestOptions.Regular11, options: TestOptions.ReleaseExe);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"2
2
Expand Down Expand Up @@ -588,7 +588,7 @@ public R()
}
}
""";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
comp.VerifyDiagnostics();
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("explicit ctor"));
verifier.VerifyIL("R..ctor()", @"
Expand Down Expand Up @@ -627,7 +627,7 @@ public R()
}
}
""";
var comp = CreateCompilation(source, targetFramework: TargetFramework.Net60);
var comp = CreateCompilation(source, targetFramework: TargetFramework.Net60, options: TestOptions.ReleaseExe);
comp.VerifyDiagnostics();
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("explicit ctor"));
verifier.VerifyIL("R..ctor()", @"
Expand Down Expand Up @@ -663,7 +663,7 @@ public R()
}
}
""";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
comp.VerifyDiagnostics();

var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("explicit ctor"));
Expand Down Expand Up @@ -699,7 +699,7 @@ public R()
}
}
""";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
comp.VerifyDiagnostics(
// (7,29): warning CS0649: Field 'R.field' is never assigned to, and will always have its default value 0
// public readonly ref int field;
Expand Down Expand Up @@ -742,7 +742,7 @@ public R()
}
}
""";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular11, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular11, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
comp.VerifyDiagnostics();
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("explicit ctor"));
verifier.VerifyIL("R..ctor()", @"
Expand Down Expand Up @@ -4042,7 +4042,7 @@ static void Main()
Console.WriteLine(s.F);
}
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"2
2
Expand Down Expand Up @@ -4447,7 +4447,7 @@ static void Main()
Console.WriteLine(s.F);
}
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"2
2
Expand Down Expand Up @@ -4857,7 +4857,7 @@ static void Main()
Console.WriteLine(s.F);
}
}";
comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"1
4
Expand Down Expand Up @@ -5013,7 +5013,7 @@ static void Main()
Console.WriteLine(s.F);
}
}";
comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"1
1
Expand Down Expand Up @@ -6054,7 +6054,7 @@ static void NewField<T>(ref R<T> r)
r.S = new S<T>();
}
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"42
42
Expand Down Expand Up @@ -6100,7 +6100,7 @@ static void Write(S<int> s, int value)
s.F = value;
}
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"42
42
Expand Down Expand Up @@ -6245,7 +6245,7 @@ static void ReadAndDiscard2<T>(in S<T> s)
// https://github.com/dotnet/roslyn/issues/62122: The dereference of a ref field
// should be emitted to IL, even if the value is ignored, because the behavior
// may be observable as a NullReferenceException.
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(""));
verifier.VerifyIL("Program.ReadAndDiscard1<T>",
@"{
Expand Down Expand Up @@ -6293,7 +6293,7 @@ static void Main()
static ref T RefReturn<T>(S<T> s) => ref s.F;
static ref readonly T RefReadonlyReturn<T>(S<T> s) => ref s.F;
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("2"));
var expectedIL =
@"{
Expand Down Expand Up @@ -6330,7 +6330,7 @@ static void Main()
static ref T RefReturn<T>(ref S<T> s) => ref s.F;
static ref readonly T RefReadonlyReturn<T>(ref S<T> s) => ref s.F;
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("2"));
var expectedIL =
@"{
Expand Down Expand Up @@ -6367,7 +6367,7 @@ static void Main()
static ref T RefReturn<T>(in S<T> s) => ref s.F;
static ref readonly T RefReadonlyReturn<T>(in S<T> s) => ref s.F;
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("2"));
var expectedIL =
@"{
Expand Down Expand Up @@ -6412,7 +6412,7 @@ static ref readonly T RefReadonlyReturn<T>(out S<T> s, ref T t)
return ref s.F;
}
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("2"));
var expectedIL =
@"{
Expand Down Expand Up @@ -6462,7 +6462,7 @@ static void Subtract(S<int> s, int offset)
s.F -= offset;
}
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"43
43
Expand Down Expand Up @@ -6531,7 +6531,7 @@ static void Main()
Console.WriteLine(x);
}}
}}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"43
43
Expand Down Expand Up @@ -6602,7 +6602,7 @@ static ref T ConditionalOperatorRef<T>(bool b, ref S<T> sx, ref S<T> sy)
return ref b ? ref sx.F : ref sy.F;
}
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"1
2
Expand Down Expand Up @@ -6665,7 +6665,7 @@ static string ConditionalAccess<T>(S<T> s)
return s.F?.ToString();
}
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"1
2
Expand Down Expand Up @@ -6804,7 +6804,7 @@ static void M<T>(in T x, in T y)
Console.WriteLine(y);
}
}";
var comp = CreateCompilation(new[] { source, UnscopedRefAttributeDefinition }, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(new[] { source, UnscopedRefAttributeDefinition }, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"1
2
Expand Down Expand Up @@ -7126,7 +7126,7 @@ static void Main()
Console.WriteLine(s.t);
}
}";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput(
@"2
2
Expand Down Expand Up @@ -12228,7 +12228,7 @@ public override string ToString()
}
}
";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
comp.VerifyDiagnostics();
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("42"));
verifier.VerifyIL("C.Main",
Expand Down Expand Up @@ -12967,7 +12967,7 @@ public void RefInitializer_Nested()
var source = @"
class C
{
void M()
static void Main()
{
int x = 42;
var r = new Container { item = { field = ref x } };
Expand All @@ -12983,10 +12983,10 @@ ref struct Item
public ref int field;
}
";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
comp.VerifyDiagnostics();
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("42"));
verifier.VerifyIL("C.M", @"
verifier.VerifyIL("C.Main", @"
{
// Code size 42 (0x2a)
.maxstack 2
Expand Down Expand Up @@ -13036,7 +13036,7 @@ ref struct R<T>
public ref S<T> field;
}
";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
comp.VerifyDiagnostics(
// (8,33): warning CS8619: Nullability of reference types in value of type 'S<object?>' doesn't match target type 'S<object>'.
// _ = new R<object> { field = ref x2 }; // 1
Expand Down Expand Up @@ -13069,7 +13069,7 @@ ref struct R
public ref S field;
}
";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
comp.VerifyDiagnostics(
// (2,5): warning CS0219: The variable 'x' is assigned but its value is never used
// int x = 42;
Expand Down Expand Up @@ -13618,7 +13618,7 @@ public override string ToString()
}
}
";
var comp = CreateCompilation(source, runtimeFeature: RuntimeFlag.ByRefFields);
var comp = CreateCompilation(source, options: TestOptions.ReleaseExe, runtimeFeature: RuntimeFlag.ByRefFields);
comp.VerifyDiagnostics();
var verifier = CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("42"));
verifier.VerifyIL("C.Main",
Expand Down