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

Issue 9866027: Error out on compile-time constants if equality is tested on bad types. (Closed)

Created:
8 years, 9 months ago by floitsch
Modified:
8 years, 9 months ago
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Error out on compile-time constants if equality is tested on bad types. Don't fold equality operation if left-hand side is a constructed object. Committed: https://code.google.com/p/dart/source/detail?r=5919

Patch Set 1 #

Total comments: 6

Patch Set 2 : Address comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+29 lines, -14 lines) Patch
M frog/leg/compile_time_constants.dart View 1 3 chunks +24 lines, -13 lines 0 comments Download
M frog/leg/operations.dart View 1 1 chunk +5 lines, -0 lines 0 comments Download
M tests/co19/co19-leg.status View 1 1 chunk +0 lines, -1 line 0 comments Download

Messages

Total messages: 4 (0 generated)
floitsch
8 years, 9 months ago (2012-03-27 06:09:39 UTC) #1
Lasse Reichstein Nielsen
drive-by LGTM https://chromiumcodereview.appspot.com/9866027/diff/1/frog/leg/compile_time_constants.dart File frog/leg/compile_time_constants.dart (right): https://chromiumcodereview.appspot.com/9866027/diff/1/frog/leg/compile_time_constants.dart#newcode903 frog/leg/compile_time_constants.dart:903: if (left.isPrimitive() && right.isPrimitive()) { Is "null" ...
8 years, 9 months ago (2012-03-27 08:12:12 UTC) #2
ngeoffray
LGTM
8 years, 9 months ago (2012-03-27 11:14:34 UTC) #3
floitsch
8 years, 9 months ago (2012-03-28 00:25:21 UTC) #4
https://chromiumcodereview.appspot.com/9866027/diff/1/frog/leg/compile_time_c...
File frog/leg/compile_time_constants.dart (right):

https://chromiumcodereview.appspot.com/9866027/diff/1/frog/leg/compile_time_c...
frog/leg/compile_time_constants.dart:903: if (left.isPrimitive() &&
right.isPrimitive()) {
On 2012/03/27 08:12:12, Lasse Reichstein Nielsen wrote:
> Is "null" a numeric, string or boolean value? It seems null isn't included in
> the spec allowances for compile-time constants comparisons.

Filed already a bug, and Gilad confirmed that null should work too.

https://chromiumcodereview.appspot.com/9866027/diff/1/frog/leg/compile_time_c...
frog/leg/compile_time_constants.dart:926: if (areIdentical === null) {
On 2012/03/27 08:12:12, Lasse Reichstein Nielsen wrote:
> Have you considered having a dedicated FoldingFailed value you can return
> instead of null. It would be infectous, so any operation using it would itself
> be a failure (e.g., call it NaCTC :), and you could avoid null checks like
this.

I have considered it, but the problem is, that you want nice error-messages.
This means that there would need to be a way to attach a node to a Constant then
(since we don't want to work conditionally) which seems not so nice.
That said I'm not convinced that this is the cleanest it can get. I just think
that currently it is good enough and not too bad.

https://chromiumcodereview.appspot.com/9866027/diff/1/frog/leg/operations.dart
File frog/leg/operations.dart (right):

https://chromiumcodereview.appspot.com/9866027/diff/1/frog/leg/operations.dar...
frog/leg/operations.dart:244: } else if (!left.isConstructedObject()) {
On 2012/03/27 08:12:12, Lasse Reichstein Nielsen wrote:
> I'd prefer 
>   else if (left.isConstructedObject()) {
>     return null;
>   } else {
>     ...
> instead of the negative test. 
> Generally, negative tests in if/else-if chains reduces readability *a lot*.
> 
> You can also drop the "else", since each branch returns.

hehe. that's what I had before. After long hesitation I move the 'return null'
to the end. Reverted.
done.

Powered by Google App Engine
This is Rietveld 408576698