User model stacking: current status

João Mendonça jf.mend at gmail.com
Fri Jun 17 18:32:15 UTC 2022


> For locals, it's pretty clear we don't have to answer, because locals
> cannot be accessed unless they are DA at the point of access. But for
> fields, we have a problem -- and for arrays, a bigger one. We can try to
> require that fields have initializers, but there are all sorts of
> situations in which a field can be read before its initializer runs. And
> arrays are much worse.


I'm sorry, Brian, are you saying that *the compiler* can't enforce
definite-assignment on non-final fields and arrays when declared with a
non-nullable no-zero type like String! or Rational!?
The user-model I layed out (my last no-subject email) depends on getting
compiler errors like these:

class C {
  String null_str;
  String! hello_str = "hello";
// error: field not initialized, String has no zero value:
  String! zero_str;
  Integer null_int;
// OK: Integer is has a zero value:
  Integer! _0_int;
  Optional<String> null_opt;
// OK: Optional has a zero value
  Optional!<String> empty_opt;
// OK: Optional.of returns an Optional!<T>
  Optional!<String> helloStr_opt = Optional.of("hello");
  Rational null_ratio;
  Rational! _2Thirds_ratio = new Rational(2, 3);
// error: field not initialized, Rational has no zero value:
  Rational! zero_ratio;
  Double[] _3_nulls = new Double[3];
  Double![] _3_zeros = new Double![3];
  String[] _2_nulls = new String[2];
  String![] _2_strings = {"a", "b"};
// error: array components not initialized, String has no zero value:
  String![] _2_zeroStrings = new String![2];
  String![] nonNullable_strings = nonNullableStrings_array();
// error: cannot convert from String[] to String![]
  String![] nullable_strings = nullableStrings_array();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-observers/attachments/20220617/6d57a591/attachment-0001.htm>


More information about the valhalla-spec-observers mailing list