dart-sdk/runtime
Paul Berry 2b8411f626 Enable language feature inference-update-2.
This language feature allows type promotion to apply to private final
fields, e.g.:

    class C {
      final int? _x;
      C(this._x);
    }
    f(C c) {
      if (c._x != null) {
        print(c._x.abs()); // (1)
      }
    }

Previously the line marked (1) would have needed to be written
`print(c._x!.abs());`.

Note that to ensure soundness, there are certain restrictions:

- Public fields don't undergo promotion (because a public field might
  be overridden by a class in some other library).

- Non-final fields don't undergo promotion (because a non-final field
  might be modified as a side effect of code executed between the type
  test and the field's usage).

- Fields that are forwarded to `noSuchMethod` in the same library
  don't undergo promotion (because there's no guarantee that
  `noSuchMethod` will return the same value on every invocation). For
  example:

    class C {
      final int? _x;
      C(this._x);
    }
    class D implements C {
      @override
      noSuchMethod(...) => ...;
    }
    f(C c) {
      if (c._x != null) {
        print(c._x.abs()); // ERROR: `c._x` might dispatch to
                           // `D.noSuchMethod`, in which case there's
                           // no guarantee that it will return a
                           // non-null value the second time it's
                           // invoked.
      }
    }

- If two classes define fields or getters of the same name, and
  promotion is not permitted for one of them, then it isn't permitted
  for the other. This is because there might be a class in some other
  library that's a subclass of both classes, causing a reference to
  one field or getter to dispatch to the other. For example:

    class C {
      final int? _x;
      C(this._x);
    }
    class D {
      int? get _x => ...;
    }
    f(C c) {
      if (c._x != null) {
        print(c._x.abs()); // ERROR: `c._x` might dispatch to `D._x`
                           // (e.g. because some library might declare
                           // `class E extends D implements C`), in
                           // which case there's no guarantee that it
                           // will return a non-null value the second
                           // time it's invoked.
      }
    }

Change-Id: Ib9183581aa0194377e38ab70d37c3e9f0bb57a75
Bug: https://github.com/dart-lang/language/issues/2020
Tested: TAP global presubmit
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/314600
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-07-28 23:56:52 +00:00
..
bin [vm] Separate for-snapshot vs embed-sources bools when compiling to kernel 2023-07-28 10:01:53 +00:00
docs [vm] Update lingering references to RawObject. 2023-07-26 21:53:49 +00:00
include [vm] Separate for-snapshot vs embed-sources bools when compiling to kernel 2023-07-28 10:01:53 +00:00
lib [vm] Update lingering references to RawObject. 2023-07-26 21:53:49 +00:00
observatory [VM/Debugger] Fix the behaviour of setting inline breakpoints in uncompiled functions 2023-07-26 17:15:36 +00:00
observatory_2 [VM/Debugger] Fix the behaviour of setting inline breakpoints in uncompiled functions 2023-07-26 17:15:36 +00:00
platform [vm] Allow non-TSAN gen_snapshot target TSAN AOT runtime 2023-07-10 11:53:58 +00:00
tests [vm, gc] Run weak processing in parallel for new-space GCs. 2023-07-26 16:45:01 +00:00
third_party Spelling pkg analyzer lib 2023-01-25 14:08:27 +00:00
tools [vm] Enable clang-tidy for arm, arm64, riscv64, product, release, precompiler. 2023-07-11 15:13:58 +00:00
vm Enable language feature inference-update-2. 2023-07-28 23:56:52 +00:00
.clang-tidy
.gitignore
BUILD.gn Add a GN flag for the non-debug optimization level 2023-07-15 14:14:59 +00:00
codereview.settings
configs.gni [Runtime] Add extra_product_deps and extra_nonproduct_deps params to "library_for_all_configs_with_compiler" template 2023-04-14 19:51:40 +00:00
CPPLINT.cfg [cpplint] Disable runtime/references lint 2023-01-23 18:21:48 +00:00
OWNERS
PRESUBMIT.py Reland "Reland "[VM] Begin supporting Perfetto file recorder"" 2023-04-18 19:39:05 +00:00
runtime_args.gni Add a GN flag for the non-debug optimization level 2023-07-15 14:14:59 +00:00