Skip to content

Commit

Permalink
Tweaks to warning level and reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
vsmenon committed Apr 3, 2015
1 parent 7321b60 commit cad0430
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pkg/dev_compiler/lib/src/codegen/reify_coercions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object>
if (node is ClosureWrap) return "Wrap";
if (node is DynamicCast) return "DynamicCast";
if (node is AssignmentCast) return "AssignmentCast";
if (node is InferableClosure) return "InferableClosure";
if (node is UninferredClosure) return "InferableClosure";
if (node is DownCastComposite) return "CompositeCast";
if (node is DownCastImplicit) return "ImplicitCast";
assert(false);
Expand Down
11 changes: 5 additions & 6 deletions pkg/dev_compiler/lib/src/info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ abstract class DownCast extends Conversion {
if (expression is FunctionExpression) {
// fromT should be an exact type - this will almost certainly fail at
// runtime.
return new InferableClosure(rules, expression, cast);
return new UninferredClosure(rules, expression, cast);
}
if (expression is InstanceCreationExpression) {
// fromT should be an exact type - this will almost certainly fail at
Expand Down Expand Up @@ -315,10 +315,9 @@ class AssignmentCast extends DownCast {
// List<String> l = [1, 2, 3]; // Inference reveals static type error
// We're marking all as warnings for now.
//

// A "down cast" on a closure literal.
class InferableClosure extends DownCast {
InferableClosure(TypeRules rules, FunctionExpression expression, Cast cast)
// TODO(vsm,leafp): Remove this.
class UninferredClosure extends DownCast {
UninferredClosure(TypeRules rules, FunctionExpression expression, Cast cast)
: super._internal(rules, expression, cast);

final Level level = Level.WARNING;
Expand Down Expand Up @@ -476,7 +475,7 @@ class DynamicInvoke extends Conversion {
DartType _getConvertedType() => rules.provider.dynamicType;

String get message => '$expression requires dynamic invoke';
Level get level => Level.WARNING;
Level get level => Level.INFO;

accept(AstVisitor visitor) {
if (visitor is ConversionVisitor) {
Expand Down
13 changes: 9 additions & 4 deletions pkg/dev_compiler/lib/src/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ String summaryToString(GlobalSummary summary) {
// Declare columns and add header
table.declareColumn('package');
table.declareColumn('AnalyzerError', abbreviate: true);
infoTypes.forEach((type) => table.declareColumn('$type', abbreviate: true));
var activeInfoTypes =
infoTypes.where((type) => counter.totals['$type'] != null);
activeInfoTypes
.forEach((type) => table.declareColumn('$type', abbreviate: true));
table.declareColumn('LinesOfCode', abbreviate: true);
table.addHeader();

Expand All @@ -207,7 +210,8 @@ String summaryToString(GlobalSummary summary) {
for (var package in counter.errorCount.keys) {
appendCount(package);
appendCount(counter.errorCount[package]['AnalyzerError']);
infoTypes.forEach((e) => appendCount(counter.errorCount[package]['$e']));
activeInfoTypes
.forEach((e) => appendCount(counter.errorCount[package]['$e']));
appendCount(counter.linesOfCode[package]);
}

Expand All @@ -216,7 +220,7 @@ String summaryToString(GlobalSummary summary) {
table.addHeader();
table.addEntry('total');
appendCount(counter.totals['AnalyzerError']);
infoTypes.forEach((type) => appendCount(counter.totals['$type']));
activeInfoTypes.forEach((type) => appendCount(counter.totals['$type']));
appendCount(counter.totalLinesOfCode);

appendPercent(count, total) {
Expand All @@ -228,7 +232,8 @@ String summaryToString(GlobalSummary summary) {
var totalLOC = counter.totalLinesOfCode;
table.addEntry('%');
appendPercent(counter.totals['AnalyzerError'], totalLOC);
infoTypes.forEach((type) => appendPercent(counter.totals['$type'], totalLOC));
activeInfoTypes
.forEach((type) => appendPercent(counter.totals['$type'], totalLOC));
appendCount(100);

return table.toString();
Expand Down
20 changes: 10 additions & 10 deletions pkg/dev_compiler/test/checker/checker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void main() {
}
void bar(a) {
foo(/*info:DynamicCast,warning:DynamicInvoke*/a.x);
foo(/*info:DynamicCast,info:DynamicInvoke*/a.x);
}
typedef DynFun(x);
Expand All @@ -40,24 +40,24 @@ void main() {
void main() {
var a = new A();
bar(a);
(/*warning:DynamicInvoke*/bar1(a));
(/*info:DynamicInvoke*/bar1(a));
var b = bar;
(/*warning:DynamicInvoke*/b(a));
(/*info:DynamicInvoke*/b(a));
var f1 = foo;
f1("hello");
dynamic f2 = foo;
(/*warning:DynamicInvoke*/f2("hello"));
(/*info:DynamicInvoke*/f2("hello"));
DynFun f3 = foo;
(/*warning:DynamicInvoke*/f3("hello"));
(/*warning:DynamicInvoke*/f3(42));
(/*info:DynamicInvoke*/f3("hello"));
(/*info:DynamicInvoke*/f3(42));
StrFun f4 = foo;
f4("hello");
a.baz1("hello");
var b1 = a.baz1;
(/*warning:DynamicInvoke*/b1("hello"));
(/*info:DynamicInvoke*/b1("hello"));
A.baz2("hello");
var b2 = A.baz2;
(/*warning:DynamicInvoke*/b2("hello"));
(/*info:DynamicInvoke*/b2("hello"));
'''
});
});
Expand Down Expand Up @@ -1852,7 +1852,7 @@ void main() {
a = a & b;
a = a ^ b;
a = a | b;
c = (/*pass should be warning:DynamicInvoke*/c + b);
c = (/*pass should be info:DynamicInvoke*/c + b);
}
'''
});
Expand Down Expand Up @@ -1922,7 +1922,7 @@ void main() {
a &= b;
a ^= b;
a |= b;
(/*warning:DynamicInvoke*/c += b);
(/*info:DynamicInvoke*/c += b);
}
'''
});
Expand Down
16 changes: 8 additions & 8 deletions pkg/dev_compiler/test/checker/inferred_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ void main() {
test() {
dynamic a = new A();
A b = /*info:DynamicCast*/a;
print(/*warning:DynamicInvoke*/a.x);
print((/*warning:DynamicInvoke*/a.x) + 2);
print(/*info:DynamicInvoke*/a.x);
print((/*info:DynamicInvoke*/a.x) + 2);
}
'''
});
Expand Down Expand Up @@ -1483,27 +1483,27 @@ void main() {
Function2<int, String> l1 = (int x) => "hello";
Function2<int, String> l2 = /*severe:StaticTypeError*/(String x) => "hello";
Function2<int, String> l3 = /*severe:StaticTypeError*/(int x) => 3;
Function2<int, String> l4 = /*warning:InferableClosure should be severe:StaticTypeError*/(int x) {return 3};
Function2<int, String> l4 = /*warning:UninferredClosure should be severe:StaticTypeError*/(int x) {return 3};
}
{
Function2<int, String> l0 = /*info:InferredTypeClosure*/(x) => null;
Function2<int, String> l1 = /*info:InferredTypeClosure*/(x) => "hello";
Function2<int, String> l2 = /*severe:StaticTypeError*/(x) => 3;
Function2<int, String> l3 = /*warning:InferableClosure should be severe:StaticTypeError*/(x) {return 3};
Function2<int, String> l3 = /*warning:UninferredClosure should be severe:StaticTypeError*/(x) {return 3};
}
{
Function2<int, List<String>> l0 = (int x) => null;
Function2<int, List<String>> l1 = /*info:InferredTypeClosure*/(int x) => ["hello"];
Function2<int, List<String>> l2 = /*severe:StaticTypeError*/(String x) => ["hello"];
Function2<int, List<String>> l3 = /*warning:InferableClosure should be severe:StaticTypeError*/(int x) => [3];
Function2<int, List<String>> l4 = /*warning:InferableClosure should be severe:StaticTypeError*/(int x) {return [3]};
Function2<int, List<String>> l3 = /*warning:UninferredClosure should be severe:StaticTypeError*/(int x) => [3];
Function2<int, List<String>> l4 = /*warning:UninferredClosure should be severe:StaticTypeError*/(int x) {return [3]};
}
{
Function2<int, int> l0 = /*info:InferredTypeClosure*/(x) => x;
Function2<int, int> l1 = /*info:InferredTypeClosure*/(x) => x+1;
Function2<int, String> l2 = /*info:InferredTypeClosure should be severe:StaticTypeError*/(x) => x;
Function2<int, String> l3 = /*info:InferredTypeClosure should be severe:StaticTypeError*/(x) => /*warning:DynamicInvoke should be pass*/x.substring(3);
Function2<String, String> l4 = /*info:InferredTypeClosure*/(x) => /*warning:DynamicInvoke should be pass*/x.substring(3);
Function2<int, String> l3 = /*info:InferredTypeClosure should be severe:StaticTypeError*/(x) => /*info:DynamicInvoke should be pass*/x.substring(3);
Function2<String, String> l4 = /*info:InferredTypeClosure*/(x) => /*info:DynamicInvoke should be pass*/x.substring(3);
}
}
'''
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/test/codegen/expect/BenchmarkBase.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Messages from compiling BenchmarkBase.dart
warning: line 63, column 7 of test/codegen/BenchmarkBase.dart: [DynamicInvoke] f() requires dynamic invoke
info: line 63, column 7 of test/codegen/BenchmarkBase.dart: [DynamicInvoke] f() requires dynamic invoke
f();
^^^
2 changes: 1 addition & 1 deletion pkg/dev_compiler/test/codegen/expect/DeltaBlue.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Messages from compiling DeltaBlue.dart
warning: line 63, column 7 of test/codegen/BenchmarkBase.dart: [DynamicInvoke] f() requires dynamic invoke
info: line 63, column 7 of test/codegen/BenchmarkBase.dart: [DynamicInvoke] f() requires dynamic invoke
f();
^^^
info: line 130, column 18 of test/codegen/DeltaBlue.dart: [DynamicCast] mark (dynamic) will need runtime check to cast to type int
Expand Down
8 changes: 4 additions & 4 deletions pkg/dev_compiler/test/codegen/expect/cascade.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Messages from compiling cascade.dart
warning: line 16, column 5 of test/codegen/cascade.dart: [DynamicInvoke] ..x() requires dynamic invoke
info: line 16, column 5 of test/codegen/cascade.dart: [DynamicInvoke] ..x() requires dynamic invoke
..x()
^^^^^
warning: line 17, column 5 of test/codegen/cascade.dart: [DynamicInvoke] ..x() requires dynamic invoke
info: line 17, column 5 of test/codegen/cascade.dart: [DynamicInvoke] ..x() requires dynamic invoke
..x();
^^^^^
warning: line 27, column 5 of test/codegen/cascade.dart: [DynamicInvoke] ..x() requires dynamic invoke
info: line 27, column 5 of test/codegen/cascade.dart: [DynamicInvoke] ..x() requires dynamic invoke
..x()
^^^^^
warning: line 28, column 5 of test/codegen/cascade.dart: [DynamicInvoke] ..x() requires dynamic invoke
info: line 28, column 5 of test/codegen/cascade.dart: [DynamicInvoke] ..x() requires dynamic invoke
..x();
^^^^^
4 changes: 2 additions & 2 deletions pkg/dev_compiler/test/codegen/expect/fieldtest.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Messages from compiling fieldtest.dart
warning: line 23, column 9 of test/codegen/fieldtest.dart: [DynamicInvoke] a.x requires dynamic invoke
info: line 23, column 9 of test/codegen/fieldtest.dart: [DynamicInvoke] a.x requires dynamic invoke
print(a.x);
^^^
info: line 24, column 10 of test/codegen/fieldtest.dart: [DynamicCast] a.x (dynamic) will need runtime check to cast to type int
return a.x;
^^^
warning: line 24, column 10 of test/codegen/fieldtest.dart: [DynamicInvoke] a.x requires dynamic invoke
info: line 24, column 10 of test/codegen/fieldtest.dart: [DynamicInvoke] a.x requires dynamic invoke
return a.x;
^^^
info: line 35, column 7 of test/codegen/fieldtest.dart: [DynamicCast] value (dynamic) will need runtime check to cast to type int
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/test/codegen/expect/methods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ warning: line 14, column 21 of test/codegen/methods.dart: [DownCastImplicit] b (
warning: line 19, column 12 of test/codegen/methods.dart: [DownCastImplicit] a + b (num) will need runtime check to cast to type int
return a + b;
^^^^^
warning: line 49, column 3 of test/codegen/methods.dart: [DynamicInvoke] f.bar("Bar's call method!") requires dynamic invoke
info: line 49, column 3 of test/codegen/methods.dart: [DynamicInvoke] f.bar("Bar's call method!") requires dynamic invoke
f.bar("Bar's call method!");
^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 comments on commit cad0430

Please sign in to comment.