nitra icon indicating copy to clipboard operation
nitra copied to clipboard

AST: Cannot use extension methods in interpolated strings

Open ssrmm opened this issue 8 years ago • 0 comments

The compiler gives two error messages with this program:

using Nitra;
  
namespace Test
{
  ast Test
  {
    Error(context, "Extension methods inside interpolated strings don't work:");
    Error(context, $"$(Foo.UnboxAndIncrement())"); // error : there is no member named `UnboxAndIncrement' in Test.Foo with type ?
                                                   // error : typing fails on ambiguity between overloads: 
    Hint(context, $"This works fine: $(FooExtensions.UnboxAndIncrement(Foo))");
    
    in Foo : Foo = Foo(2);
  }
}
using System.Console;

namespace Test
{
  public module FooExtensions
  {
    public UnboxAndIncrement(this foo : Foo) : int
    {
      foo.Bar + 1;
    }
  }
  
  [Record]
  public class Foo
  {
    public Bar : int { get; }
  }
  
  public module FooTester
  {
    public Test(foo : Foo) : void
    {
      WriteLine($"This also works fine: $(foo.UnboxAndIncrement())");   
    }
  }
}

In addition to the error messages, I also get several hints about System.Convert.ToString() overloads.

Note that this is Nitra specific. As you can see from the WriteLine() in the last line of the second file, it works correctly in Nemerle.

ssrmm avatar Nov 15 '16 10:11 ssrmm