-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #74 Prevent a crash when there's a complex expression to the left…
… of the dot in an extension method
- Loading branch information
Showing
6 changed files
with
85 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace Generator.Tests; | ||
|
||
public class ExtensionMethodTests | ||
{ | ||
[Fact] | ||
public Task UnwrapGenericExtensionMethod() => """ | ||
using System.Drawing; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Zomp.SyncMethodGenerator.IntegrationTests | ||
{ | ||
using Extensi.ons123; | ||
partial class Extensions | ||
{ | ||
[CreateSyncVersion] | ||
public static async Task HasGenericExtensionAsync(object o, CancellationToken ct) | ||
{ | ||
var z = o.TryGetValue<Point>(out var item); | ||
} | ||
|
||
[CreateSyncVersion] | ||
public static async Task HasGeneric2ExtensionAsync(object o, CancellationToken ct) | ||
{ | ||
var z = o.TryGetValue<Point, PointF>(out var _, out var _1); | ||
} | ||
} | ||
} | ||
|
||
namespace Extensi.ons123 | ||
{ | ||
internal static class MyExtensionClass | ||
{ | ||
public static bool TryGetValue<T>(this object _, out T? item) | ||
{ | ||
item = default; | ||
return false; | ||
} | ||
|
||
public static bool TryGetValue<T1, T2>(this object _, out T1? item1, out T2? item2) | ||
{ | ||
item1 = default; | ||
item2 = default; | ||
return false; | ||
} | ||
} | ||
} | ||
""".Verify(sourceType: SourceType.Full); | ||
|
||
[Fact] | ||
public Task LeftOfTheDotTest() => """ | ||
namespace Tests; | ||
|
||
internal class Bar | ||
{ | ||
public static Bar Create() => new Bar(); | ||
} | ||
|
||
partial class Class | ||
{ | ||
[Zomp.SyncMethodGenerator.CreateSyncVersion] | ||
public async Task MethodAsync() | ||
{ | ||
_ = Bar.Create()?.DoSomething(); | ||
} | ||
} | ||
|
||
internal static class BarExtension | ||
{ | ||
public static Bar DoSomething(this Bar bar) => bar; | ||
} | ||
""".Verify(sourceType: SourceType.Full); | ||
} |
11 changes: 11 additions & 0 deletions
11
...sts/Snapshots/ExtensionMethodTests.LeftOfTheDotTest#Tests.Class.MethodAsync.g.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//HintName: Tests.Class.MethodAsync.g.cs | ||
// <auto-generated/> | ||
#nullable enable | ||
namespace Tests; | ||
partial class Class | ||
{ | ||
public void Method() | ||
{ | ||
_ = ((global::System.Func<global::Tests.Bar?,global::Tests.Bar?>)((param)=>(object?)param == null?(global::Tests.Bar?)null: global::Tests.BarExtension.DoSomething(param)))(global::Tests.Bar.Create()); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters