Export to GitHub

dwscript - issue #492

It should be possible to use an external var symbol as command.


Posted on Nov 3, 2014 by Helpful Elephant

Possible usage of external var: 1. Write value: EXTVAR := s; 2. Read value: s := EXTVAR; 3. Read value (and discard Result): EXTVAR;

Currently only 1 and 2 are possible.

Since EXTVAR is not just a simple storage, but has code, it is desireable to run the associated code without caring for the result.

Justification ReadExternalVar is called with IsWrite=true on the assumption that an assignment operator would follow. When this assumption is proven wrong the compiler should assume the script writer wants to read from the external var (even if the result is discarded).

I suggest changing TdwsCompiler.ReadExternalVar

from: if Writing: if followed by ttASSIGN: return write-function if (not followed by ttASSIGN) and (type-is-one-that-should-be-read): return read-function if Reading: return read-function

to: if Writing: if followed by ttASSIGN: return assign-function if not followed by ttASSIGN: // imply read if name is not assigned to. return read-function if Reading: return read-function

Comment #1

Posted on Nov 3, 2014 by Happy Rabbit

Would it really be desirable or is it more likely to lead to faulty code not generating compile time errors?

The external vars were more intended to act as a bridge to outside-of-script data, so to follow the "principle of minimum surprise", they should ideally have no side-effect (like property reads/getters), and thus such use would likely be an error.

Status: WontFix

Labels:
Type-Defect Priority-Medium