nitra
nitra copied to clipboard
Compiler error when setting out property of symbol outside the symbol
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.
OK. Two things come to mind:
- The error message should probably be more descriptive, like
error: Output dependent properties of a symbol cannot be assigned from a declaration
- 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'");
}