Skip to content

AS3/TS ExternsGenerator incorrectly generate public var for default read-only properties #10

@pngdrift

Description

@pngdrift

Describe the bug
Fields declared in Haxe as public var type(default, null):String are incorrectly generated as public var in AS3/TS externs, instead of being accessible only via getter.

To Reproduce
Steps to reproduce the behavior:

  1. Run this Royale sample
package {
  import openfl.display.Bitmap;
  import openfl.display.BitmapData;
  import openfl.display.Sprite;
  import openfl.ui.Keyboard;
  import openfl.ui.Multitouch;

  public class App extends Sprite {

    public function App() {
      super();
      var bitmapData:BitmapData = new BitmapData(32,32,false,0xFF0000);
      bitmapData.perlinNoise(2,2,2,2,true,false);

      /* Every line below should produce read-only property errors */
      bitmapData.width = 111;
      bitmapData.height = 55;
      parent = new Sprite();
      Multitouch.maxTouchPoints = 99;
      Keyboard.capsLock = true;
      /* end */

      addChild(new Bitmap(bitmapData));
      trace(parent);
      trace(Multitouch.maxTouchPoints);
      trace(Keyboard.capsLock);
    }
  }
}
  1. Observe that compilation succeeds instead of producing errors.

Expected behavior
Errors should be shown: Property _x_ is read-only.

OpenFL Targets
AS3 Royale, TypeScript

Additional context
I think the problem is here

var isAccessor = read == AccCall || write == AccCall || mustBeAccessor(classField.name, interfaces);

var isAccessor = read == AccCall || write == AccCall || mustBeAccessor(classField.name, interfaces);

I tried changing the line to:

var isAccessor = read == AccCall || write == AccCall || mustBeAccessor(classField.name, interfaces)
					|| (read != write && (read == AccNormal  || write == AccNormal));

This seems fixes the issue, but then in ByteArray, length property is generated as getter instead of public var. I’m not sure why.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions