diff --git a/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs b/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs index 31534e200..8dd377f14 100644 --- a/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs +++ b/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs @@ -25,7 +25,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) provider.IsCsWinRTCcwLookupTableGeneratorEnabled()) ); - var assemblyName = context.CompilationProvider.Select(static (compilation, _) => GeneratorHelper.EscapeTypeNameForIdentifier(compilation.AssemblyName)); + var assemblyName = context.CompilationProvider.Select(static (compilation, _) => GeneratorHelper.EscapeAssemblyNameForIdentifier(compilation.AssemblyName)); var propertiesAndAssemblyName = properties.Combine(assemblyName); @@ -1107,7 +1107,7 @@ private static EquatableArray GetVtableAttributesToAddOnLookupT if (context.Node is InvocationExpressionSyntax invocation) { - var invocationSymbol = context.SemanticModel.GetSymbolInfo(invocation.Expression).Symbol; + var invocationSymbol = context.SemanticModel.GetSymbolInfo(invocation).Symbol; if (invocationSymbol is IMethodSymbol methodSymbol && // Filter checks for boxing and casts to ones calling CsWinRT projected functions and // functions within same assembly. Functions within same assembly can take a boxed value diff --git a/src/Authoring/WinRT.SourceGenerator/Helper.cs b/src/Authoring/WinRT.SourceGenerator/Helper.cs index 00d9195b7..7de19b9da 100644 --- a/src/Authoring/WinRT.SourceGenerator/Helper.cs +++ b/src/Authoring/WinRT.SourceGenerator/Helper.cs @@ -1060,6 +1060,11 @@ public static string GetAbiMarshalerType(string type, string abiType, TypeKind k throw new ArgumentException(); } + public static string EscapeAssemblyNameForIdentifier(string typeName) + { + return Regex.Replace(typeName, """[^a-zA-Z0-9_]""", "_"); + } + public static string EscapeTypeNameForIdentifier(string typeName) { return Regex.Replace(typeName, """[(\ |:<>,\.\-@;+'^!`)]""", "_"); diff --git a/src/Authoring/WinRT.SourceGenerator/WinRTAotCodeFixer.cs b/src/Authoring/WinRT.SourceGenerator/WinRTAotCodeFixer.cs index 030c41c11..1d104ae18 100644 --- a/src/Authoring/WinRT.SourceGenerator/WinRTAotCodeFixer.cs +++ b/src/Authoring/WinRT.SourceGenerator/WinRTAotCodeFixer.cs @@ -136,7 +136,7 @@ public override void Initialize(AnalysisContext context) if (context.Node is InvocationExpressionSyntax invocation) { - var invocationSymbol = context.SemanticModel.GetSymbolInfo(invocation.Expression).Symbol; + var invocationSymbol = context.SemanticModel.GetSymbolInfo(invocation).Symbol; if (invocationSymbol is IMethodSymbol methodSymbol) { var taskAdapter = GeneratorHelper.GetTaskAdapterIfAsyncMethod(methodSymbol); diff --git a/src/Tests/FunctionalTests/Collections/Program.cs b/src/Tests/FunctionalTests/Collections/Program.cs index d0e1ac77e..3adab7b20 100644 --- a/src/Tests/FunctionalTests/Collections/Program.cs +++ b/src/Tests/FunctionalTests/Collections/Program.cs @@ -264,12 +264,23 @@ return 101; } +// Testing to ensure no exceptions from any of the analyzers while building. +Action s = (a, b) => { _ = a + b; }; +ActionToFunction(s)(2, 3); + return 100; static bool SequencesEqual(IEnumerable x, params IEnumerable[] list) => list.All((y) => x.SequenceEqual(y)); static bool AllEqual(T[] x, params T[][] list) => list.All((y) => x.SequenceEqual(y)); +static Func ActionToFunction(Action action) => + (a1, a2) => + { + action(a1, a2); + return a1; + }; + sealed partial class CustomClass : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged;