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

Can't serve web project with 2.19 #51128

Open
jodinathan opened this issue Jan 25, 2023 · 15 comments
Open

Can't serve web project with 2.19 #51128

jodinathan opened this issue Jan 25, 2023 · 15 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.

Comments

@jodinathan
Copy link

webdev serve:

INFO] Entrypoint:Generating build script...
[INFO] Entrypoint:Generating build script completed, took 962ms

[INFO] Bootstrap:Precompiling build script......
[WARNING] Bootstrap:
../../../../../.pub-cache/hosted/pub.dev/build_modules-4.0.6/lib/src/module_cache.dart:21:70: Error: The method 'toJson' isn't defined for the class 'Object?'.
 - 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing method, or defining a method named 'toJson'.
    (m) => MetaModule.fromJson(_deserialize(m)), (m) => _serialize(m.toJson()));
                                                                     ^^^^^^
../../../../../.pub-cache/hosted/pub.dev/build_modules-4.0.6/lib/src/module_cache.dart:24:66: Error: The method 'toJson' isn't defined for the class 'Object?'.
 - 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing method, or defining a method named 'toJson'.
    (m) => Module.fromJson(_deserialize(m)), (m) => _serialize(m.toJson()));
                                                                 ^^^^^^
[INFO] Bootstrap:Precompiling build script... completed, took 3.8s

[SEVERE] Bootstrap:
Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.

Dart SDK version: 2.19.0 (stable) (Mon Jan 23 11:29:09 2023 -0800) on "macos_x64"

@a-siva a-siva added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jan 25, 2023
@kevmoo
Copy link
Member

kevmoo commented Jan 25, 2023

@jakemac53 ? @natebosch ?

@jakemac53
Copy link
Contributor

I can repro this on build_modules version 4.0.6 but not 4.0.7, although I don't see an explicit mention of a fix or remember one. But updating to 4.0.7 should fix this for you?

@jakemac53
Copy link
Contributor

I also don't see any recent changes to the failing line of code so I am pretty confused by why this error is showing up

@jodinathan
Copy link
Author

I also don't see any recent changes to the failing line of code so I am pretty confused by why this error is showing up

weirdly it doesn't happen with 2.19.0-255.2.beta

But updating to 4.0.7 should fix this for you?

I can't use 4.0.7 because it bumps analyzer to 5.1.0.

The analyzer CHANGELOG could have more information on how to fix depreciation and removals.

Really tuff to make Angular compiler compatible with it :/

@natebosch
Copy link
Member

natebosch commented Jan 25, 2023

I confirmed that the language version change from 2.17 to 2.18 fixes the error. I think this is because of an improvement to inference (which was primarily aimed at making fold work nicer)

I also confirmed with a minimal reproduction that the 2.19.0 SDK introduces an error that was missing in previous SDKs.

Here is a minimal repro:

T? inferFromArgs<T>(
        T Function(List<int>) fromBytes, List<int> Function(T) toBytes) =>
    null;
final x = inferFromArgs(String.fromCharCodes, (m) => m.codeUnits);
void main() {}

This runs without error on the following language/SDK combinations:

SDK 2.18.0 SDK 2.19.0
@dart 2.17
@dart 2.18

What seems to throw off the analyzer (in both SDKs) and CFE (in 2.18.0) is the T? return type. If I change the return type to Null both the analyzer and CFE report an error for 2.17 language version, and not 2.18 language version.
With the T? return type analyzer does not report an error with any SDK version - only the CFE surfaces the error.

@stereotype441 - can you confirm that this is intended to be a static error for language version earlier than 2.18?

@stereotype441
Copy link
Member

@natebosch thanks for the minimal repro. It's not immediately clear to me what's going on here. I will set aside some time tomorrow to dig into this.

@jakemac53
Copy link
Contributor

I can't use 4.0.7 because it bumps analyzer to 5.1.0.

Note that in general, if you can't upgrade your analyzer, then you probably don't want to upgrade your SDK either. The analyzer version you have may not fully support the language changes in the SDK.

@jodinathan
Copy link
Author

@jakemac53 you are correct, that is why we are migrating to analyzer 5.4.0 now.

(However we stumbled upon another weird error: dart-lang/build#3444)

@stereotype441
Copy link
Member

I dug into @natebosch's minimal repro a bit, and I believe it is correct (according to the language spec) to report an error when the language version is 2.17. (The reason is because in language versions 2.17 and earlier, we don't have horizontal inference, so the context used in inferring the closure (m) => m.codeUnits is List<int> Function(?) (where ? represents the "unknown type"). Therefore, the type inferred for m should be the greatest closure of ?, namely Object?. And since Object? doesn't support the .codeUnits getter, this should be a compile-time error.

I also figured out why the analyzer is failing to report an error, and wrote up a separate issue for it: #51137

What I don't know is why the front end only reports the error with version 2.19.0, and not with 2.18.0. @johnniwinther or @chloestefantsova, would one of you mind having a look into why the front end behaviour changed?

@jodinathan
Copy link
Author

I am closing this issue because we were able to migrate our Angular projects and 2.19 is working ok.
Dunno if should stay open thought

@stereotype441
Copy link
Member

@jodinathan I'm glad to hear that you were able to get your projects to work.

I'm going to go ahead and re-open this issue, because as @natebosch pointed out in #51128 (comment), we do have a difference between the behaviour of the front end between versions 2.18 and 2.19, and I think it would be good for us to figure out why the behaviour differs, make sure the current behaviour is what we want, and (if necessary) make a retroactive breaking-change announcement to help out others who run into the same issue you did.

@stereotype441 stereotype441 reopened this Jan 26, 2023
@nshahan nshahan added area-front-end Use area-front-end for front end / CFE / kernel format related issues. and removed area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels Jan 27, 2023
@greglittlefield-wf
Copy link
Contributor

I can repro this on build_modules version 4.0.6 but not 4.0.7, although I don't see an explicit mention of a fix or remember one. But updating to 4.0.7 should fix this for you?

I also don't see any recent changes to the failing line of code so I am pretty confused by why this error is showing up

@jakemac53 When digging into this issue in dart-lang/build#3412, I noticed that build_modules raised its SDK constraint from 2.14 to 2.18 in 4.0.7, opting that package into the newer language version. I wonder if that explains why the behavior is different between 4.0.6 and 4.0.7?

@jakemac53
Copy link
Contributor

Correct, there was a change to inference that broke the package. Bumping the language version fixed that issue.

@insinfo
Copy link

insinfo commented Mar 23, 2023

@jodinathan

How did you manage to resolve this? Because I'm also having this problem with AngularDart 7.1.1 and Dart 2.19.5

name: new_sali_frontend

environment:   
  sdk: '>=2.18.0 <3.0.0'

dependencies:   
  ngdart: ^7.1.1
  ngforms: ^4.1.1
  ngrouter: ^3.1.1      
  http: any  
  js: any
  pdf: ^3.9.0
  barcode: ^2.2.3  
  ngsecurity:
   git:
      ref: main
      url: https://github.com/angulardart-community/ngsecurity.git 
 
  
dev_dependencies:     
  sass_builder: ^2.1.2  
  build_runner: any
  build_test: any
  build_web_compilers: any
  pedantic: any
  test: any

@stereotype441
Is there already a solution for this in progress?

@jakemac53
Copy link
Contributor

@insinfo are you on build_modules version 4.0.7 or greater?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants