Skip to content

Commit

Permalink
Workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkiGibson committed Dec 9, 2024
1 parent 9598e68 commit ddc9b84
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions src/Compilers/CSharp/Test/Semantic/Semantics/InterceptorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ partial class C
[Fact]
public void ArgumentLabels()
{
var source = """
var source = ("""
using System;
class C
Expand All @@ -1680,9 +1680,9 @@ public static void Main()
c.InterceptableMethod(s2: "World", s1: "Hello ");
}
}
""";
""", "Program.cs");
var locations = GetInterceptableLocations(source);
var interceptors = $$"""
var interceptors = ($$"""
using System.Runtime.CompilerServices;
using System;
Expand All @@ -1691,7 +1691,7 @@ static class D
[InterceptsLocation({{GetAttributeArgs(locations[1]!)}})]
public static void Interceptor1(this C c, string s1, string s2) { Console.Write("interceptor " + s1 + s2); }
}
""";
""", "Interceptors.cs");
var verifier = CompileAndVerify([source, interceptors, s_attributesSource], parseOptions: RegularWithInterceptors, expectedOutput: "interceptor Hello World");
verifier.VerifyDiagnostics();
}
Expand Down Expand Up @@ -3965,7 +3965,7 @@ static class D
public void SignatureMismatch_08()
{
// nint/IntPtr difference
var source = """
var source = ("""
using System;
class C
Expand All @@ -3987,9 +3987,9 @@ public static void Main()
c.Method1(default!);
}
}
""";
""", "Program.cs");
var locations = GetInterceptableLocations(source);
var interceptors = $$"""
var interceptors = ($$"""
using System.Runtime.CompilerServices;
using System;
Expand All @@ -4003,25 +4003,7 @@ static class D
[InterceptsLocation({{GetAttributeArgs(locations[3]!)}})]
public static void Interceptor2(this C s, nint param2) => Console.Write(2);
}
""";

// TODO2: 'InterceptableLocation' is not finding the correct call with this specific set of inputs. change ANYTHING about the content of 'source' and expected errors will be reported.
// It doesn't appear to be a hash collision issue, unsure yet what it really is.

var comp = CreateCompilation([source, interceptors, s_attributesSource], parseOptions: RegularWithInterceptors);
comp.VerifyEmitDiagnostics(
// (6,6): warning CS9154: Intercepting a call to 'C.Method1(nint)' with interceptor 'D.Interceptor1(C, IntPtr)', but the signatures do not match.
// [InterceptsLocation(1, "7SN+G7Nd46k5We+z0k74ffUAAAA=")] // 1
Diagnostic(ErrorCode.WRN_InterceptorSignatureMismatch, "InterceptsLocation").WithArguments("C.Method1(nint)", "D.Interceptor1(C, System.IntPtr)").WithLocation(6, 6),
// (7,6): error CS9144: Cannot intercept method 'Console.Write(int)' with interceptor 'D.Interceptor1(C, IntPtr)' because the signatures do not match.
// [InterceptsLocation(1, "7SN+G7Nd46k5We+z0k74fRMBAAA=")]
Diagnostic(ErrorCode.ERR_InterceptorSignatureMismatch, "InterceptsLocation").WithArguments("System.Console.Write(int)", "D.Interceptor1(C, System.IntPtr)").WithLocation(7, 6),
// (10,6): warning CS9154: Intercepting a call to 'C.Method2(IntPtr)' with interceptor 'D.Interceptor2(C, nint)', but the signatures do not match.
// [InterceptsLocation(1, "7SN+G7Nd46k5We+z0k74fTMBAAA=")] // 2
Diagnostic(ErrorCode.WRN_InterceptorSignatureMismatch, "InterceptsLocation").WithArguments("C.Method2(System.IntPtr)", "D.Interceptor2(C, nint)").WithLocation(10, 6));

// TODO2: re-enable
#if false
""", "Interceptors.cs");
var verifier = CompileAndVerify([source, interceptors, s_attributesSource], parseOptions: RegularWithInterceptors, expectedOutput: "1122");
verifier.VerifyDiagnostics(
// (6,6): warning CS9154: Intercepting a call to 'C.Method1(nint)' with interceptor 'D.Interceptor1(C, IntPtr)', but the signatures do not match.
Expand All @@ -4030,7 +4012,6 @@ static class D
// (10,6): warning CS9154: Intercepting a call to 'C.Method2(IntPtr)' with interceptor 'D.Interceptor2(C, nint)', but the signatures do not match.
// [InterceptsLocation(1, "3ONc0QK7vNwCujpTORn5YjUBAAA=")] // 2
Diagnostic(ErrorCode.WRN_InterceptorSignatureMismatch, "InterceptsLocation").WithArguments("C.Method2(System.IntPtr)", "D.Interceptor2(C, nint)").WithLocation(10, 6));
#endif
}

[Fact]
Expand Down

0 comments on commit ddc9b84

Please sign in to comment.