rsdn / nitra

Nitra is a language workbench

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiler error when setting out property of symbol outside the symbol

ssrmm opened this issue · comments

commented
namespace Test
{
  declaration Foo
  {
    symbol
    {
      out Bar : string; // error : Output dependent property 'Bar' is never assigned to.
    }
    
    Symbol.Bar = "Bar";
  }
}

This is by design. Use in property in this case.

commented

OK. Two things come to mind:

  1. The error message should probably be more descriptive, like error: Output dependent properties of a symbol cannot be assigned from a declaration
  2. The following two examples achieve the same behaviour by introducing some boilerplate. Shouldn't those be disallowed then as well?
declaration TestAst
{
  symbol
  {
    in Temp : string;
    out Bar : string = Temp;
  }
  
  Symbol.Temp = "Bar";
}

declaration TestAst
{
  symbol
  {
    out Bar : string = FirstDeclarationOrDefault.GetBarFromDeclaration();
  }
  
  out Bar : string = "Bar";
}
public static GetBarFromDeclaration(this ast : Declaration) : string
{
  | TestAst as testAst => testAst.Bar;
  | _ => assert(false, "Can only be called on 'TestAst'");
}