nitra icon indicating copy to clipboard operation
nitra copied to clipboard

Compiler error when setting out property of symbol outside the symbol

Open ssrmm opened this issue 8 years ago • 2 comments

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

ssrmm avatar Dec 21 '16 13:12 ssrmm

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

VladD2 avatar Dec 21 '16 19:12 VladD2

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'");
}

ssrmm avatar Dec 22 '16 10:12 ssrmm