Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Issue 10916002: Change switch to give errors when cases don't follow the newest syntax. (Closed)

Created:
8 years, 3 months ago by Lasse Reichstein Nielsen
Modified:
8 years, 3 months ago
Reviewers:
floitsch, ngeoffray
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Change switch to give warnings when cases don't follow the newest syntax. The current implementation still falls back on if-else-if dispatch if the case expressions are not compile-time constants. It also falls back if the expressions fail to follow the specification for any other reason. The specification requires that case expressions: - Are compile-time constants. - All have the same type and are instances of the same class. - Do not override Object.operator==. For the last one, I've made exceptions for int/double/String. Function constants are rejected due to overriding operator==. I'm not sure they do yet, but they will eventually. Map and List are accepted. All constant Map/List instances are expected to be instances of the same class. If we later decide to make them override operator==, we'll have to reject them too. If we decide to have a special class for some List/Map constants, we'll let it override runtimeType to hide it. Type equality is only checked as far as the constants know their type. Type parameters are not included in the test since I don't think they are recorded in the compile-time constant (I could be wrong). The new switch semantics are still on "hold", so this change retains the old version too (which accepted any expression). When we want to remove that, it's a matter of making the warnings into errors and remove the fallback (the current content of visitSwitchStatement after the call to tryBuildConstantSwitch). The validation of switch cases should really happen during resolution if possible. I'll try to figure out how to move it there in a later CL. Committed: https://code.google.com/p/dart/source/detail?r=12189

Patch Set 1 #

Total comments: 16

Patch Set 2 : Address review comments #

Patch Set 3 : Merge to head #

Patch Set 4 : use .compileType on elements. #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+177 lines, -37 lines) Patch
M lib/compiler/implementation/compile_time_constants.dart View 1 2 3 7 chunks +24 lines, -2 lines 3 comments Download
M lib/compiler/implementation/enqueue.dart View 1 2 3 1 chunk +2 lines, -2 lines 0 comments Download
M lib/compiler/implementation/ssa/builder.dart View 1 2 4 chunks +69 lines, -28 lines 0 comments Download
M lib/compiler/implementation/warnings.dart View 1 2 3 1 chunk +8 lines, -5 lines 0 comments Download
M tests/language/switch_test.dart View 1 1 chunk +74 lines, -0 lines 0 comments Download

Messages

Total messages: 13 (0 generated)
Lasse Reichstein Nielsen
8 years, 3 months ago (2012-08-30 06:10:52 UTC) #1
ngeoffray
https://chromiumcodereview.appspot.com/10916002/diff/1/lib/compiler/implementation/compile_time_constants.dart File lib/compiler/implementation/compile_time_constants.dart (right): https://chromiumcodereview.appspot.com/10916002/diff/1/lib/compiler/implementation/compile_time_constants.dart#newcode27 lib/compiler/implementation/compile_time_constants.dart:27: abstract bool isSameType(Constant constant); I'd prefer having something consistant ...
8 years, 3 months ago (2012-08-30 07:29:13 UTC) #2
Lasse Reichstein Nielsen
https://chromiumcodereview.appspot.com/10916002/diff/1/lib/compiler/implementation/compile_time_constants.dart File lib/compiler/implementation/compile_time_constants.dart (right): https://chromiumcodereview.appspot.com/10916002/diff/1/lib/compiler/implementation/compile_time_constants.dart#newcode27 lib/compiler/implementation/compile_time_constants.dart:27: abstract bool isSameType(Constant constant); Seems reasonable if there is ...
8 years, 3 months ago (2012-08-30 10:54:25 UTC) #3
ngeoffray
https://chromiumcodereview.appspot.com/10916002/diff/1/lib/compiler/implementation/compile_time_constants.dart File lib/compiler/implementation/compile_time_constants.dart (right): https://chromiumcodereview.appspot.com/10916002/diff/1/lib/compiler/implementation/compile_time_constants.dart#newcode27 lib/compiler/implementation/compile_time_constants.dart:27: abstract bool isSameType(Constant constant); On 2012/08/30 10:54:25, Lasse Reichstein ...
8 years, 3 months ago (2012-08-30 11:07:13 UTC) #4
floitsch
LGTM. The description seems contradictory: "Change switch to give errors when cases don't follow the ...
8 years, 3 months ago (2012-08-30 14:08:18 UTC) #5
Lasse Reichstein Nielsen
I get some "queue is closed" errors when using .computeType on elements in the builder. ...
8 years, 3 months ago (2012-09-03 09:12:55 UTC) #6
ngeoffray
Lasse, are you still having problems committing this change, because of the queue error?
8 years, 3 months ago (2012-09-06 08:15:59 UTC) #7
Lasse Reichstein Nielsen
I haven't gotten back to this. I was trying to move the test to the ...
8 years, 3 months ago (2012-09-06 08:20:25 UTC) #8
ngeoffray
On 2012/09/06 08:20:25, Lasse Reichstein Nielsen wrote: > I haven't gotten back to this. I ...
8 years, 3 months ago (2012-09-06 08:23:54 UTC) #9
ngeoffray
http://codereview.chromium.org/10916002/diff/6/lib/compiler/implementation/compile_time_constants.dart File lib/compiler/implementation/compile_time_constants.dart (right): http://codereview.chromium.org/10916002/diff/6/lib/compiler/implementation/compile_time_constants.dart#newcode27 lib/compiler/implementation/compile_time_constants.dart:27: abstract DartType computeType(ConstantHandler handler); Please take a Compiler here ...
8 years, 3 months ago (2012-09-06 09:28:55 UTC) #10
Lasse Reichstein Nielsen
http://codereview.chromium.org/10916002/diff/6/lib/compiler/implementation/compile_time_constants.dart File lib/compiler/implementation/compile_time_constants.dart (right): http://codereview.chromium.org/10916002/diff/6/lib/compiler/implementation/compile_time_constants.dart#newcode27 lib/compiler/implementation/compile_time_constants.dart:27: abstract DartType computeType(ConstantHandler handler); Good point. I was trying ...
8 years, 3 months ago (2012-09-06 12:03:36 UTC) #11
Lasse Reichstein Nielsen
http://codereview.chromium.org/10916002/diff/6/lib/compiler/implementation/compile_time_constants.dart File lib/compiler/implementation/compile_time_constants.dart (right): http://codereview.chromium.org/10916002/diff/6/lib/compiler/implementation/compile_time_constants.dart#newcode27 lib/compiler/implementation/compile_time_constants.dart:27: abstract DartType computeType(ConstantHandler handler); Done by someone else. Yey.
8 years, 3 months ago (2012-09-11 12:20:23 UTC) #12
Lasse Reichstein Nielsen
8 years, 3 months ago (2012-09-11 12:20:24 UTC) #13

          

Powered by Google App Engine
This is Rietveld 408576698