Skip to content

Variable shadowing and priorities #298

@brice-morin

Description

@brice-morin

Consider the following ThingML function:

function f(a : Integer) do
  var b : Integer = a - 1
  ...
  var a : Integer = 0
  ...
end

The parser does not complain, but yields a surprising result...

In b = a - 1, a refers to var a, which is declared afterwards. IMHO, it should refer to the parameter a of the function, since it has not been shadowed yet.... Anyway, I think:

  • shadowing is dangerous and should not be allowed i.e., it should not be possible to declare var a if it has been previously declared in a variable or a parameter.
  • in an action block, it should not be possible to refer to variables defined later on... action blocks being purely sequential...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions