Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Commit 8668399

Browse files
committed
fix(Compiler): Add a workaround for #908, "extra" type inference for 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
1 parent fda4d5e commit 8668399

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

angular/lib/src/source_gen/template_compiler/compile_metadata.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ class CompileTypeMetadataVisitor
117117
}
118118
}
119119
final token = dart_objects.getField(provider, 'token');
120+
121+
// Workaround for analyzer bug.
122+
// https://github.com/dart-lang/angular/issues/917
123+
if (multiType == null &&
124+
$OpaqueToken.isAssignableFromType(token.type) &&
125+
token.type.typeArguments.isNotEmpty) {
126+
// If we see a Provider<dynamic> (no generic type), but the token is a
127+
// typed OpaqueToken<T>, pretend that the Provider was actually inferred
128+
// as Provider<T>.
129+
final opaqueTokenGenericType = token.type.typeArguments.first.element;
130+
multiType = _getCompileTypeMetadata(opaqueTokenGenericType);
131+
}
132+
120133
return new CompileProviderMetadata(
121134
token: _token(token),
122135
useClass: _getUseClass(provider, token),

0 commit comments

Comments
 (0)