ponyc icon indicating copy to clipboard operation
ponyc copied to clipboard

repeat field initializaton could be improved

Open SeanTAllen opened this issue 3 years ago • 0 comments
trafficstars

The following code will always initialize _s:

actor Main
  var _s: (String | None)

  new create(env: Env) =>
    var i: USize = 0
    repeat
      _s = i.string()
      break
    until i >= 5 else
      None
    end

however because of how refer_repeat is implemented, this could will result in an error as the existence of break anywhere in the repeat body means that the else must also initialize all fields.

The current error is:

Error:
/home/sean/pony-scratch/3283/main.pony:2:3: field left undefined in constructor
  var _s: (String | None)
  ^
Error:
/home/sean/pony-scratch/3283/main.pony:4:3: constructor with undefined fields is here
  new create(env: Env) =>
  ^

There's a general lack of tests around repeat and field initialization so before any work is done on this, tests that validate the existing otherwise correct behavior should be added.

SeanTAllen avatar Feb 15 '22 02:02 SeanTAllen