-
Notifications
You must be signed in to change notification settings - Fork 232
Analyzer summaries missing generic types for DartObject #908
Comments
Both places are using an In bazel we use summaries for files outside the current package, in build_runner we always read Dart sources, never summaries. |
Interestingly enough, this worked internally a while back :-/ |
Could be a regression in the AnalysisContext in that case - I think we're likely getting older versions of the analyzer package externally than what is rolled internally. If you can build a test case you might want to see if you can try against older versions of analyzer internally. |
For folks reading this thread: INTERNALLY = 0.31.2-alpha.0 |
My understanding was that top levels don't have inference, they get implicit dynamic. It seems like for const values we do some kind of inference, though... We did just change const values around a bit in order to support asserts in initializers? |
Yeah, it works as of If you need a better reproduction case, I'm happy to write one. |
Its my understanding that this does not have any inference... |
Its a little hard to see here, but the failing travis sees it: https://api.travis-ci.org/v3/job/342583283/log.txt
i.e. externally, we read this provider as EDIT: I will add that one of these uses summaries of dependencies (internally, with Bazel) and one of these does not (externally, with Build Runner). That may or may not matter? |
In order to avoid this blocking the sync, I'll add a work-around for now @alorenzen. |
Added a general-case regression test to track addressing #908 correctly. PiperOrigin-RevId: 186484795
Added a general-case regression test to track addressing #908 correctly. PiperOrigin-RevId: 186484795
Added a general-case regression test to track addressing #908 correctly. PiperOrigin-RevId: 186484795
Ping @MichaelRFairhurst @scheglov could I get some help? I added a regression test here: The skipped case passes externally, but fails internally. |
This should almost certainly be inferred. We do toplevel inference, and this looks like a straightforward example of something we should catch, unless I'm missing something. There are a lot of known bugs and unimplemented bits in the analyzer (since it was intended to only be implemented in the new front end), but we certainly shouldn't be regressing here. Unfortunately this is sometimes very sensitive to multiple files and analysis order, but if there's any way you can get a small repro that would be great. Also, file an issue in the sdk if you haven't already. |
@leafpetersen I tried implementing the simplest repro possible: import 'provider.dart';
import 'token.dart';
const tokenOfString = const Token<String>();
const implicitProviderOfString = const Provider(tokenOfString);
const explicitProviderOfString = const Provider<String>(tokenOfString); @TestOn('vm')
import 'package:analyzer/dart/constant/value.dart';
import 'package:build/build.dart';
import 'package:build_test/build_test.dart';
import 'package:test/test.dart';
void main() {
final asset = new AssetId('top_level_analyzer', 'lib/library.dart');
DartObject explicitProviderOfString;
DartObject implicitProviderOfString;
setUpAll(() async {
final library = await resolveAsset(asset, (r) => r.libraryFor(asset));
final fields = library.definingCompilationUnit.topLevelVariables;;
explicitProviderOfString = fields[1].computeConstantValue();
implicitProviderOfString = fields[2].computeConstantValue();
});
test('should resolve explicitProviderOfString', () async {
expect(explicitProviderOfString.type.toString(), 'Provider<String>');
});
test('should resolve implicitProviderOfString', () async {
expect(implicitProviderOfString.type.toString(), 'Provider<String>');
});
} ... and this works externally, just fine, with both:
... so now I'm thinking its related to summaries (Bazel uses). I'll try and write the same test internally and see if I get different results tomorrow, I hope I can figure something out. |
@stereotype441 took a look at this. I'm going to port the above test internally, where it fails, and then share with the team to see if we can make some progress. Update a little later today. |
From what I can tell... this works fine internally, too. It's likely something very subtle and not directly related to the analyzer, or build, but I really appreciate everyone looking at this and trying to help diagnose the problem(s). I'll ping again if I have a fix or further questions. |
I'm closing this, as we are just landing a workaround instead. |
This test fails internally when DDC enforces type checks for ... it shouldn't. |
I believe the underlying cause is dart-lang/sdk#32290. |
Wow! Thanks @stereotype441! I think I can add a workaround, again, until we have a fix. |
After further investigation, there is some regression in resolving types from the angular_forms library from within the _goldens library, but only internally for the golden file generator ... woo, a mouth-full. It makes sense to just trim this specific case out, since we have coverage of the type inference feature in other test cases, and not worry about trying to resolve another package from within the golden files. [After speaking to multiple members of the analyzer team, it seems like both order, types (summaries versus source files), and other very subtle things could cause this, and since we are on the deprecated AnalysisContext for builders anyway, it doesn't make sense to focus on this specific case.] ... also refactor that golden file, while we are at it! PiperOrigin-RevId: 186656275
…tokens. After this CL, we will infer, in the view compiler: `Provider<dynamic>(OpaqueToken<T>)` as `Provider<T>(OpaqueToken<T>)` This isn't strictly right, but its better than emitting incorrect types (dynamic), which can block Dart2. Once #908 is fixed, we can revert this change. PiperOrigin-RevId: 186788142
After further investigation, there is some regression in resolving types from the angular_forms library from within the _goldens library, but only internally for the golden file generator ... woo, a mouth-full. It makes sense to just trim this specific case out, since we have coverage of the type inference feature in other test cases, and not worry about trying to resolve another package from within the golden files. [After speaking to multiple members of the analyzer team, it seems like both order, types (summaries versus source files), and other very subtle things could cause this, and since we are on the deprecated AnalysisContext for builders anyway, it doesn't make sense to focus on this specific case.] ... also refactor that golden file, while we are at it! PiperOrigin-RevId: 186656275
…tokens. After this CL, we will infer, in the view compiler: `Provider<dynamic>(OpaqueToken<T>)` as `Provider<T>(OpaqueToken<T>)` This isn't strictly right, but its better than emitting incorrect types (dynamic), which can block Dart2. Once #908 is fixed, we can revert this change. PiperOrigin-RevId: 186788142
After further investigation, there is some regression in resolving types from the angular_forms library from within the _goldens library, but only internally for the golden file generator ... woo, a mouth-full. It makes sense to just trim this specific case out, since we have coverage of the type inference feature in other test cases, and not worry about trying to resolve another package from within the golden files. [After speaking to multiple members of the analyzer team, it seems like both order, types (summaries versus source files), and other very subtle things could cause this, and since we are on the deprecated AnalysisContext for builders anyway, it doesn't make sense to focus on this specific case.] ... also refactor that golden file, while we are at it! PiperOrigin-RevId: 186656275
…tokens. After this CL, we will infer, in the view compiler: `Provider<dynamic>(OpaqueToken<T>)` as `Provider<T>(OpaqueToken<T>)` This isn't strictly right, but its better than emitting incorrect types (dynamic), which can block Dart2. Once #908 is fixed, we can revert this change. PiperOrigin-RevId: 186788142
After further investigation, there is some regression in resolving types from the angular_forms library from within the _goldens library, but only internally for the golden file generator ... woo, a mouth-full. It makes sense to just trim this specific case out, since we have coverage of the type inference feature in other test cases, and not worry about trying to resolve another package from within the golden files. [After speaking to multiple members of the analyzer team, it seems like both order, types (summaries versus source files), and other very subtle things could cause this, and since we are on the deprecated AnalysisContext for builders anyway, it doesn't make sense to focus on this specific case.] ... also refactor that golden file, while we are at it! PiperOrigin-RevId: 186656275
…tokens. After this CL, we will infer, in the view compiler: `Provider<dynamic>(OpaqueToken<T>)` as `Provider<T>(OpaqueToken<T>)` This isn't strictly right, but its better than emitting incorrect types (dynamic), which can block Dart2. Once #908 is fixed, we can revert this change. PiperOrigin-RevId: 186788142
After further investigation, there is some regression in resolving types from the angular_forms library from within the _goldens library, but only internally for the golden file generator ... woo, a mouth-full. It makes sense to just trim this specific case out, since we have coverage of the type inference feature in other test cases, and not worry about trying to resolve another package from within the golden files. [After speaking to multiple members of the analyzer team, it seems like both order, types (summaries versus source files), and other very subtle things could cause this, and since we are on the deprecated AnalysisContext for builders anyway, it doesn't make sense to focus on this specific case.] ... also refactor that golden file, while we are at it! PiperOrigin-RevId: 186656275
…tokens. After this CL, we will infer, in the view compiler: `Provider<dynamic>(OpaqueToken<T>)` as `Provider<T>(OpaqueToken<T>)` This isn't strictly right, but its better than emitting incorrect types (dynamic), which can block Dart2. Once #908 is fixed, we can revert this change. PiperOrigin-RevId: 186788142
We have a class called
MultiToken
and another calledExistingProvider
:https://github.com/dart-lang/angular/blob/1abcb5c62fc8a8267f1abdb2081d07f40567c56f/angular/lib/src/core/di/opaque_token.dart#L62-L74
https://github.com/dart-lang/angular/blob/1abcb5c62fc8a8267f1abdb2081d07f40567c56f/angular/lib/src/di/providers.dart#L241-L265
This pattern was created in order to correctly "infer" what the type of a given DI provider should be, but also not require manual type annotations (use flowing type inference from
OpaqueToken<T>
->ExistingProvider<T>
->Provider<T>
(T
):When analyzing this during our compilation,
T
ofDEFAULT_VALUE_ACCESSOR
isdynamic
internally (withbazel_codegen
) and (correctly)ControlValueAccessor
externally (withbuild_runner
). This is causing our sync to fail on travis:https://api.travis-ci.org/v3/job/342583283/log.txt
If I manually type (don't rely on inference), it works as intended in both places:
It's also possible this is due to different analyzer versions/configuration? I know top-level inference is inconsistent without using Dart 2 semantics, but I'm very confused why this works properly externally but not internally.
/cc @natebosch @scheglov @alorenzen
The text was updated successfully, but these errors were encountered: