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

Null Safety hole with array access #11585

Open
kLabz opened this issue Feb 20, 2024 · 4 comments
Open

Null Safety hole with array access #11585

kLabz opened this issue Feb 20, 2024 · 4 comments
Labels

Comments

@kLabz
Copy link
Contributor

kLabz commented Feb 20, 2024

Array access will return null on index not found, yet return type is T, not Null<T>:

@:nullSafety(Strict)
class Test {
  static function main() {
    var s:String = foo(42);
    trace(s == null); // true
    // s = null; // Null safety: Cannot assign nullable value here.
  }
  
  static function foo(i:Int) {
    var arr:Array<String> = [];
    return arr[i];
  }
}

https://try.haxe.org/#1DeFA9FA

@kLabz kLabz added the feature-null-safety Null safety label Feb 20, 2024
@RealyUniqueName
Copy link
Member

There was a PR merged to address this issue: #6825
But it was reverted because of #6847

@kLabz
Copy link
Contributor Author

kLabz commented Feb 20, 2024

That's unfortunate 😕

Maybe now that null safety is in the compiler we could revive this but only when null safety is Strict?
cc @ncannasse

@Simn
Copy link
Member

Simn commented Feb 20, 2024

From my understanding one of the main problems with that PR was that it introduced target differences.

@9Morello
Copy link

@kLabz that sounds like a good compromise to me

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

4 participants