flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.17k stars 26.65k forks source link

Flutter web in profile and realease mode, considere specific variable always null #147482

Open apps-auth opened 2 weeks ago

apps-auth commented 2 weeks ago

Steps to reproduce

It has a large flutter system that has worked normally for years, I recently updated flutter to version 3.19.5 and since then I have had several problems only in the web version in profile and release mode, which do not happen anywhere else.

Everyone was able to adapt, but this last one caught my attention, apparently Flutter, when converting the code to js, is assuming that a variable is always null, below are some images: logs image

Below is the generated javascript code:

copyWith$9$cavalo$conditions$id$name$optionalSelected$optionalSelectedDefaultId$optionals$optionalsIds$visualizationIsConditioned(cavalo, conditions, id, $name, optionalSelected, optionalSelectedDefaultId, optionals, optionalsIds, visualizationIsConditioned) {
      var t1, t2, t3, t4, t5, t6, t7, t8, t9, _this = this;
      A.print("copyWith(): this.nameForUser: " + A.S(_this.nameForUser));
      A.print("copyWith(): cavalo: " + A.S(cavalo));
      A.print("copyWith(): nameForUser.runtimeType: " + A.S(cavalo) + " = " + B.JSNull_methods.get$runtimeType(cavalo).toString$0(0) + " = true");
      A.print("copyWith(): nameForUser: " + A.S(cavalo));
      A.print("copyWith(): this.name: " + A.S(_this.name));
      A.print("copyWith(): name: " + A.S($name));
      A.print("copyWith(): name.runtimeType: " + J.get$runtimeType$($name).toString$0(0));
      A.print("*****");
      t1 = id == null ? _this.id : id;
      t2 = _this.nameForUser;
      if (optionalsIds == null) {
        t3 = _this.optionalsIds;
        if (t3 == null)
          t3 = [];
        t3 = A.List_List$from(t3, true, type$.String);
      } else
        t3 = optionalsIds;
      t4 = $name == null ? _this.name : $name;
      if (optionals == null) {
        t5 = _this.optionals;
        if (t5 == null)
          t5 = [];
        t5 = A.List_List$from(t5, true, type$.ProductAcessorie);
      } else
        t5 = optionals;
      if (optionalSelected == null) {
        t6 = _this.optionalSelected;
        t6 = t6 == null ? null : t6.copyWith$0();
      } else
        t6 = optionalSelected;
      t7 = optionalSelectedDefaultId == null ? _this.optionalSelectedDefaultId : optionalSelectedDefaultId;
      t8 = visualizationIsConditioned == null ? _this.visualizationIsConditioned : visualizationIsConditioned;
      t9 = _this.conditionIsValid;
      return A.ProductAcessoriesGroup$(t9, conditions == null ? _this.ProductOptionalSelectorGroupBase_conditions : conditions, t1, t4, t2, t6, t7, t5, t3, t8);
    },
    copyWith$1$id(id) {
      var _null = null;
      return this.copyWith$9$cavalo$conditions$id$name$optionalSelected$optionalSelectedDefaultId$optionals$optionalsIds$visualizationIsConditioned(_null, _null, id, _null, _null, _null, _null, _null, _null);
    },
    copyWith$1$cavalo(cavalo) {
      var _null = null;
      return this.copyWith$9$cavalo$conditions$id$name$optionalSelected$optionalSelectedDefaultId$optionals$optionalsIds$visualizationIsConditioned(cavalo, _null, _null, _null, _null, _null, _null, _null, _null);
    },

In the lines A.print("copyWith(): nameForUser.runtimeType: " + A.S(cavalo) + " = " + B.JSNull_methods.get$runtimeType(cavalo).toString$0(0) + " = true"); when print the value calls the function "A.S()" but when print the type calls the function "B.JSNull_methods"

On the line t1 = id == null ? _this.id : id; it checks if the id is different from null, already on the line t2 = _this.nameForUser; it disregards the parameter passed in the function

I've already tried changing the name and position of the variable but nothing works. I found two similar problems: https://github.com/dart-lang/sdk/issues/44692 https://github.com/dart-lang/sdk/issues/44692

Expected results

That the code does not automatically consider the variable null

Actual results

When converting to javascript, dart is assuming the variable as always null

Flutter Doctor output

[√] Flutter (Channel stable, 3.19.5, on Microsoft Windows [versÆo 10.0.22631.3447], locale pt-BR) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop Windows apps (Visual Studio Community 2019 16.11.32) [!] Android Studio (version 2021.2) X Unable to determine bundled Java version. [√] Android Studio (version 2023.2) [√] VS Code (version 1.88.1) [√] Connected device (3 available) [√] Network resources

darshankawar commented 2 weeks ago

Thanks for the report @apps-auth Is there a way for you to provide us reproducible code that shows this behavior ?