Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nullsafety] null safety errors in inlined code #7897

Open
Gama11 opened this issue Feb 28, 2019 · 2 comments
Open

[nullsafety] null safety errors in inlined code #7897

Gama11 opened this issue Feb 28, 2019 · 2 comments
Assignees
Labels
Milestone

Comments

@Gama11
Copy link
Member

Gama11 commented Feb 28, 2019

#7821 is related to this, but it deserves its own issue.

Inlined code currently breaks the package filters of --macro nullSafety() / @:nullSafety, which is a real problem if the inlined code isn't controlled by you. Especially considering that the std lib isn't null safe yet. For instance, this prevents you from using regexes together with null safety on the Python target:

class Main {
	@:nullSafety
	static function main() {
		~/foo/.match("bar");
	}
}
>haxe -main Main -python foo.py
Main.hx:4: characters 3-22 : Null safety: Cannot assign nullable value here.

Of course Python's EReg should be updated, but that's just a band-aid and I expect there's many more such cases, a lot of them in libraries rather than the std lib.

@Gama11 Gama11 changed the title [null safety] null safety errors in inlined code [nullsafety] null safety errors in inlined code Feb 28, 2019
@RealyUniqueName
Copy link
Member

RealyUniqueName commented Feb 28, 2019

The only workaround I can suggest right now is using @:nullSafety(Off) at expression level:

@:nullSafety(Off) ~/foo/.match("bar");

The way compiler assigns position info to inlined expressions is also a problem with debuggers:

class Tools {
  static public inline function traverse(collection:Array<Int>, callback:Int->Void) {
    for(i in collection) {
      doSomething(i);
      callback(i);
      doAnotherThing(i);
    }
  }
}

class CompletelyDifferentModule {
  static function debugMe() {
    // upon reaching this line you cannot step into `traverse`.
    // you just keep smashing "step over" button 
    // in debugger at this line for `4 * (amount of lines in traverse)` times
    Tools.traverse([1, 2, 3, 4], i -> trace(i)); 
    trace('done');
  }
}

@Gama11
Copy link
Member Author

Gama11 commented Feb 28, 2019

Right, I remember that FD used to inject --no-inline for Flash/Debug builds to make things behave nicely.. :/

Gama11 added a commit to Gama11/haxe that referenced this issue Mar 7, 2019
This is a particularly annoying case of HaxeFoundation#7897 since it's implementation is `inline` on some platforms like JS.
@Simn Simn added this to the Design milestone May 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants