Skip to content

Commit 2652875

Browse files
author
John Messerly
committed
some fixes for --strong warnings
I didn't go all the way, in case we want to change some of these. Thoughts? [email protected] Review URL: https://codereview.chromium.org/1245013002 .
1 parent 7252228 commit 2652875

12 files changed

+152
-133
lines changed

pkg/dev_compiler/lib/src/analysis_context.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'options.dart';
2121
/// using [createSourceFactory] to set up its [SourceFactory].
2222
AnalysisContext createAnalysisContextWithSources(
2323
StrongModeOptions strongOptions, SourceResolverOptions srcOptions,
24-
{DartUriResolver sdkResolver, List fileResolvers}) {
24+
{DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) {
2525
var srcFactory = createSourceFactory(srcOptions,
2626
sdkResolver: sdkResolver, fileResolvers: fileResolvers);
2727
return createAnalysisContext(strongOptions)..sourceFactory = srcFactory;
@@ -55,7 +55,7 @@ SourceFactory createSourceFactory(SourceResolverOptions options,
5555
? createMockSdkResolver(mockSdkSources)
5656
: createSdkPathResolver(options.dartSdkPath);
5757

58-
var resolvers = [];
58+
var resolvers = <UriResolver>[];
5959
if (options.customUrlMappings.isNotEmpty) {
6060
resolvers.add(new CustomUriResolver(options.customUrlMappings));
6161
}

pkg/dev_compiler/lib/src/checker/checker.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class _OverrideChecker {
120120

121121
// Check all interfaces reachable from the `implements` clause in the
122122
// current class against definitions here and in superclasses.
123-
var localInterfaces = new Set();
123+
var localInterfaces = new Set<InterfaceType>();
124124
var type = node.element.type;
125125
type.interfaces.forEach((i) => find(i, localInterfaces));
126126
_checkInterfacesOverrides(node, localInterfaces, seen,
@@ -129,7 +129,7 @@ class _OverrideChecker {
129129
// Check also how we override locally the interfaces from parent classes if
130130
// the parent class is abstract. Otherwise, these will be checked as
131131
// overrides on the concrete superclass.
132-
var superInterfaces = new Set();
132+
var superInterfaces = new Set<InterfaceType>();
133133
var parent = type.superclass;
134134
// TODO(sigmund): we don't seem to be reporting the analyzer error that a
135135
// non-abstract class is not implementing an interface. See
@@ -239,7 +239,7 @@ class _OverrideChecker {
239239
}
240240
} else {
241241
if ((member as MethodDeclaration).isStatic) continue;
242-
var method = member.element;
242+
var method = (member as MethodDeclaration).element;
243243
if (seen.contains(method.name)) continue;
244244
if (_checkSingleOverride(method, baseType, member, member)) {
245245
seen.add(method.name);
@@ -841,7 +841,7 @@ class CodeChecker extends RecursiveAstVisitor {
841841
var element = node.staticElement;
842842
// Method invocation.
843843
if (element is MethodElement) {
844-
var type = element.type as FunctionType;
844+
var type = element.type;
845845
// Analyzer should enforce number of parameter types, but check in
846846
// case we have erroneous input.
847847
if (type.normalParameterTypes.isNotEmpty) {
@@ -882,7 +882,7 @@ class CodeChecker extends RecursiveAstVisitor {
882882
} else {
883883
var element = node.staticElement;
884884
if (element is MethodElement) {
885-
var type = element.type as FunctionType;
885+
var type = element.type;
886886
// Analyzer should enforce number of parameter types, but check in
887887
// case we have erroneous input.
888888
if (type.normalParameterTypes.isNotEmpty) {

pkg/dev_compiler/lib/src/checker/rules.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,12 @@ class RestrictedRules extends TypeRules {
470470
/// Returns `true` if the expression is a dynamic function call or method
471471
/// invocation.
472472
bool isDynamicCall(Expression call) {
473-
var t = getTypeAsCaller(call);
473+
var ft = getTypeAsCaller(call);
474474
// TODO(leafp): This will currently return true if t is Function
475475
// This is probably the most correct thing to do for now, since
476476
// this code is also used by the back end. Maybe revisit at some
477477
// point?
478-
if (t == null) return true;
478+
if (ft == null) return true;
479479
// Dynamic as the parameter type is treated as bottom. A function with
480480
// a dynamic parameter type requires a dynamic call in general.
481481
// However, as an optimization, if we have an original definition, we know
@@ -488,7 +488,6 @@ class RestrictedRules extends TypeRules {
488488
}
489489
}
490490

491-
var ft = t as FunctionType;
492491
return _anyParameterType(ft, (pt) => pt.isDynamic);
493492
}
494493
}

pkg/dev_compiler/lib/src/codegen/ast_builder.dart

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ class AstBuilder {
2121
return RawAstBuilder.identifierFromString(name);
2222
}
2323

24-
static PrefixedIdentifier prefixedIdentifier(Identifier pre, Identifier id) {
24+
static PrefixedIdentifier prefixedIdentifier(
25+
SimpleIdentifier pre, SimpleIdentifier id) {
2526
return RawAstBuilder.prefixedIdentifier(pre, id);
2627
}
2728

28-
static TypeParameter typeParameter(Identifier name, [TypeName bound = null]) {
29+
static TypeParameter typeParameter(SimpleIdentifier name,
30+
[TypeName bound = null]) {
2931
return RawAstBuilder.typeParameter(name, bound);
3032
}
3133

@@ -47,8 +49,9 @@ class AstBuilder {
4749
return RawAstBuilder.typeName(id, argList);
4850
}
4951

50-
static FunctionTypeAlias functionTypeAlias(TypeName ret, Identifier name,
51-
List<TypeParameter> tParams, List<FormalParameter> params) {
52+
static FunctionTypeAlias functionTypeAlias(TypeName ret,
53+
SimpleIdentifier name, List<TypeParameter> tParams,
54+
List<FormalParameter> params) {
5255
TypeParameterList tps =
5356
(tParams.length == 0) ? null : typeParameterList(tParams);
5457
FormalParameterList fps = formalParameterList(params);
@@ -248,17 +251,18 @@ class AstBuilder {
248251
return RawAstBuilder.block(statements);
249252
}
250253

251-
static MethodDeclaration blockMethodDeclaration(TypeName rt, Identifier m,
252-
List<FormalParameter> params, List<Statement> statements,
253-
{bool isStatic: false}) {
254+
static MethodDeclaration blockMethodDeclaration(TypeName rt,
255+
SimpleIdentifier m, List<FormalParameter> params,
256+
List<Statement> statements, {bool isStatic: false}) {
254257
FormalParameterList fl = formalParameterList(params);
255258
Block b = block(statements);
256259
BlockFunctionBody body = RawAstBuilder.blockFunctionBody(b);
257260
return RawAstBuilder.methodDeclaration(rt, m, fl, body, isStatic: isStatic);
258261
}
259262

260-
static FunctionDeclaration blockFunctionDeclaration(TypeName rt, Identifier f,
261-
List<FormalParameter> params, List<Statement> statements) {
263+
static FunctionDeclaration blockFunctionDeclaration(TypeName rt,
264+
SimpleIdentifier f, List<FormalParameter> params,
265+
List<Statement> statements) {
262266
FunctionExpression fexp = blockFunction(params, statements);
263267
return RawAstBuilder.functionDeclaration(rt, f, fexp);
264268
}
@@ -279,7 +283,7 @@ class AstBuilder {
279283
}
280284

281285
static FunctionDeclarationStatement functionDeclarationStatement(
282-
TypeName rType, Identifier name, FunctionExpression fe) {
286+
TypeName rType, SimpleIdentifier name, FunctionExpression fe) {
283287
var fd = RawAstBuilder.functionDeclaration(rType, name, fe);
284288
return RawAstBuilder.functionDeclarationStatement(fd);
285289
}
@@ -295,12 +299,12 @@ class AstBuilder {
295299
return application(parenthesize(l), <Expression>[e1]);
296300
}
297301

298-
static SimpleFormalParameter simpleFormal(Identifier v, TypeName t) {
302+
static SimpleFormalParameter simpleFormal(SimpleIdentifier v, TypeName t) {
299303
return RawAstBuilder.simpleFormalParameter(v, t);
300304
}
301305

302306
static FunctionTypedFormalParameter functionTypedFormal(
303-
TypeName ret, Identifier v, List<FormalParameter> params) {
307+
TypeName ret, SimpleIdentifier v, List<FormalParameter> params) {
304308
FormalParameterList ps = formalParameterList(params);
305309
return RawAstBuilder.functionTypedFormalParameter(ret, v, ps);
306310
}
@@ -334,12 +338,14 @@ class RawAstBuilder {
334338
return new SimpleIdentifier(token);
335339
}
336340

337-
static PrefixedIdentifier prefixedIdentifier(Identifier pre, Identifier id) {
341+
static PrefixedIdentifier prefixedIdentifier(
342+
SimpleIdentifier pre, SimpleIdentifier id) {
338343
Token period = new Token(TokenType.PERIOD, 0);
339344
return new PrefixedIdentifier(pre, period, id);
340345
}
341346

342-
static TypeParameter typeParameter(Identifier name, [TypeName bound = null]) {
347+
static TypeParameter typeParameter(SimpleIdentifier name,
348+
[TypeName bound = null]) {
343349
Token keyword =
344350
(bound == null) ? null : new KeywordToken(Keyword.EXTENDS, 0);
345351
return new TypeParameter(null, null, name, keyword, bound);
@@ -367,8 +373,8 @@ class RawAstBuilder {
367373
return new TypeName(id, l);
368374
}
369375

370-
static FunctionTypeAlias functionTypeAlias(TypeName ret, Identifier name,
371-
TypeParameterList tps, FormalParameterList fps) {
376+
static FunctionTypeAlias functionTypeAlias(TypeName ret,
377+
SimpleIdentifier name, TypeParameterList tps, FormalParameterList fps) {
372378
Token semi = new Token(TokenType.SEMICOLON, 0);
373379
Token td = new KeywordToken(Keyword.TYPEDEF, 0);
374380
return new FunctionTypeAlias(null, null, td, ret, name, tps, fps, semi);
@@ -468,13 +474,12 @@ class RawAstBuilder {
468474
}
469475

470476
static FunctionDeclaration functionDeclaration(
471-
TypeName rt, Identifier f, FunctionExpression fexp) {
477+
TypeName rt, SimpleIdentifier f, FunctionExpression fexp) {
472478
return new FunctionDeclaration(null, null, null, rt, null, f, fexp);
473479
}
474480

475-
static MethodDeclaration methodDeclaration(
476-
TypeName rt, Identifier m, FormalParameterList fl, FunctionBody body,
477-
{bool isStatic: false}) {
481+
static MethodDeclaration methodDeclaration(TypeName rt, SimpleIdentifier m,
482+
FormalParameterList fl, FunctionBody body, {bool isStatic: false}) {
478483
Token st = isStatic ? new KeywordToken(Keyword.STATIC, 0) : null;
479484
return new MethodDeclaration(
480485
null, null, null, st, rt, null, null, m, null, fl, body);
@@ -496,12 +501,13 @@ class RawAstBuilder {
496501
return new ReturnStatement(ret, e, semi);
497502
}
498503

499-
static SimpleFormalParameter simpleFormalParameter(Identifier v, TypeName t) {
504+
static SimpleFormalParameter simpleFormalParameter(
505+
SimpleIdentifier v, TypeName t) {
500506
return new SimpleFormalParameter(null, <Annotation>[], null, t, v);
501507
}
502508

503509
static FunctionTypedFormalParameter functionTypedFormalParameter(
504-
TypeName ret, Identifier v, FormalParameterList ps) {
510+
TypeName ret, SimpleIdentifier v, FormalParameterList ps) {
505511
return new FunctionTypedFormalParameter(
506512
null, <Annotation>[], ret, v, null, ps);
507513
}
@@ -518,11 +524,11 @@ class RawAstBuilder {
518524
return new DefaultFormalParameter(fp, ParameterKind.NAMED, null, null);
519525
}
520526

521-
static NamedExpression namedParameter(Identifier s, Expression e) {
527+
static NamedExpression namedParameter(SimpleIdentifier s, Expression e) {
522528
return namedExpression(s, e);
523529
}
524530

525-
static NamedExpression namedExpression(Identifier s, Expression e) {
531+
static NamedExpression namedExpression(SimpleIdentifier s, Expression e) {
526532
Label l = new Label(s, new Token(TokenType.COLON, 0));
527533
return new NamedExpression(l, e);
528534
}

pkg/dev_compiler/lib/src/codegen/code_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ abstract class CodeGenerator {
5151
// below.
5252
list.sort((s1, s2) => s2.length - s1.length);
5353
return list;
54-
}();
54+
}() as List<String>;
5555

5656
static String _dirToPrefix(String dir) {
5757
dir = path.absolute(dir);

0 commit comments

Comments
 (0)