Skip to content

CFE produces the following error in flutter code when constant_update_2018 flag is turned on #36564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
a-siva opened this issue Apr 11, 2019 · 7 comments
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures
Milestone

Comments

@a-siva
Copy link
Contributor

a-siva commented Apr 11, 2019

Turning on constant_update_2018 flag and running flutter tests produces the following error:

Compiler message:
file:///usr/local/google/home/asiva/workspace/flutter-roll/flutter/packages/flut
ter/lib/src/painting/flutter_logo.dart:56:26: Error: Binary operator '=='
requires receiver constant 'FlutterLogoStyle {index: 0, #lib1::_name:
"FlutterLogoStyle.markOnly"}' of type 'Null', 'bool', 'int', 'double', or
'String', but was of type 'FlutterLogoStyle'.
 - 'FlutterLogoStyle' is from 'package:flutter/src/painting/flutter_logo.dart'
 ('file:///usr/local/google/home/asiva/workspace/flutter-roll/flutter/packages/f
 lutter/lib/src/painting/flutter_logo.dart').
       _position = style == FlutterLogoStyle.markOnly ? 0.0 : style ==
       FlutterLogoStyle.horizontal ? 1.0 : -1.0, // ignore:
       CONST_EVAL_TYPE_BOOL_NUM_STRING

The relevant code is as follows:

import 'dart:math' as math;
import 'dart:typed_data';
import 'dart:ui' as ui show Gradient, TextBox, lerpDouble;

import 'package:flutter/foundation.dart';

import 'alignment.dart';
import 'basic_types.dart';
import 'box_fit.dart';
import 'decoration.dart';
import 'edge_insets.dart';
import 'image_provider.dart';
import 'text_painter.dart';
import 'text_span.dart';
import 'text_style.dart';

/// Possible ways to draw Flutter's logo.
enum FlutterLogoStyle {
  /// Show only Flutter's logo, not the "Flutter" label.
  ///
  /// This is the default behavior for [FlutterLogoDecoration] objects.
  markOnly,

  /// Show Flutter's logo on the left, and the "Flutter" label to its right.
  horizontal,

  /// Show Flutter's logo above the "Flutter" label.
  stacked,
}

/// An immutable description of how to paint Flutter's logo.
class FlutterLogoDecoration extends Decoration {
  /// Creates a decoration that knows how to paint Flutter's logo.
  ///
  /// The [lightColor] and [darkColor] are used to fill the logo. The [style]
  /// controls whether and where to draw the "Flutter" label. If one is shown,
  /// the [textColor] controls the color of the label.
  ///
  /// The [lightColor], [darkColor], [textColor], [style], and [margin]
  /// arguments must not be null.
  const FlutterLogoDecoration({
    this.lightColor = const Color(0xFF42A5F5), // Colors.blue[400]
    this.darkColor = const Color(0xFF0D47A1), // Colors.blue[900]
    this.textColor = const Color(0xFF616161),
    this.style = FlutterLogoStyle.markOnly,
    this.margin = EdgeInsets.zero,
  }) : assert(lightColor != null),
       assert(darkColor != null),
       assert(textColor != null),
       assert(style != null),
       assert(margin != null),
       _position = style == FlutterLogoStyle.markOnly ? 0.0 : style == FlutterLo
goStyle.horizontal ? 1.0 : -1.0, // ignore: CONST_EVAL_TYPE_BOOL_NUM_STRING
       // (see https://github.com/dart-lang/sdk/issues/26980 for details about t
hat ignore statement)
       _opacity = 1.0;

  const FlutterLogoDecoration._(this.lightColor, this.darkColor, this.textColor,
 this.style, this.margin, this._position, this._opacity);
 ................
 ................
   /// Whether and where to draw the "Flutter" text. By default, only the logo
  /// itself is drawn.
  // This property isn't actually used when painting. It's only really used to
  // set the internal _position property.
  final FlutterLogoStyle style;
  ..................
  ..................
}
@a-siva a-siva added the legacy-area-front-end Legacy: Use area-dart-model instead. label Apr 11, 2019
@a-siva a-siva added this to the Dart 2.3 milestone Apr 11, 2019
@a-siva
Copy link
Contributor Author

a-siva commented Apr 11, 2019

Was able to reduce the test as follows

/// Possible ways to draw Flutter's logo.
enum FlutterLogoStyle {
  /// Show only Flutter's logo, not the "Flutter" label.
  ///
  /// This is the default behavior for [FlutterLogoDecoration] objects.
  markOnly,

  /// Show Flutter's logo on the left, and the "Flutter" label to its right.
  horizontal,

  /// Show Flutter's logo above the "Flutter" label.
  stacked,
}

class FlutterLogoDecoration {
  const FlutterLogoDecoration(
    { this.style = FlutterLogoStyle.markOnly }
  ) : assert (style != null),
      _position = style == FlutterLogoStyle.markOnly ? 0.0 : style == FlutterLog
oStyle.horizontal ? 1.0 : -1.0, // ignore: CONST_EVAL_TYPE_BOOL_NUM_STRING
      _opacity = 1.0;

  final double _opacity;
  final double _position;
  final FlutterLogoStyle style;
}

main() {
  const FlutterLogoDecoration config = FlutterLogoDecoration();
  print(config);
}

This produces the following error when constant__update_2018 flag is used

file:///tmp/junk1.dart:19:25: Error: Binary operator '==' requires receiver constant 'FlutterLogoStyle {index: 0, #lib1::_name: "FlutterLogoStyle.markOnly"}' of type 'Null', 'bool', 'int', 'double', or 'String', but was of type 'FlutterLogoStyle'.
 - 'FlutterLogoStyle' is from 'file:///tmp/junk1.dart'.
      _position = style == FlutterLogoStyle.markOnly ? 0.0 : style == FlutterLogoStyle.horizontal ? 1.0 : -1.0, // ignore: CONST_EVAL_TYPE_BOOL_NUM_STRING
                        ^
file:///tmp/junk1.dart:28:31: Context: While analyzing:
  const FlutterLogoDecoration config = FlutterLogoDecoration();
                              ^
file:///tmp/junk1.dart:19:25: Error: Binary operator '==' requires receiver constant 'FlutterLogoStyle {index: 0, #lib1::_name: "FlutterLogoStyle.markOnly"}' of type 'Null', 'bool', 'int', 'double', or 'String', but was of type 'FlutterLogoStyle'.
 - 'FlutterLogoStyle' is from 'file:///tmp/junk1.dart'.
      _position = style == FlutterLogoStyle.markOnly ? 0.0 : style == FlutterLogoStyle.horizontal ? 1.0 : -1.0, // ignore: CONST_EVAL_TYPE_BOOL_NUM_STRING
                        ^

Without the flag it runs fine:

sivalinuxmach[sdk]>out/DebugX64/dart /tmp/junk1.dart
Instance of 'FlutterLogoDecoration'

@a-siva a-siva added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Apr 11, 2019
@kmillikin
Copy link

This is invalid code, that's why the analyzer is told to shut up with // ignore: CONST_EVAL_TYPE_BOOL_NUM_STRING.

The error message we give seems kind of cryptic, but the important part is that the spec requires "receiver ... of type 'Null', 'bool', 'int', 'double', or 'String', but was of type 'FlutterLogoStyle'".

If we had a spec change, it would be easy enough to change the constant evaluator.

/cc @lrhn

@kmillikin
Copy link

This is really a duplicate of #26980.

@kmillikin
Copy link

The front-end constant evaluator fixes a bug in the VM (that it accepted this code). Flutter will see it as a regression because the Dart platform they were using previously allowed this code. This is despite the fact that it was knowingly exploiting a VM bug.

I'm not sure how we want to proceed from here. The workaround in Flutter code is to use identical instead of operator==.

I talked to @lrhn and we're not going to get a spec update for this issue for Dart 2.3.

We could provide a flag that the VM target could use to instruct us to be bug compatible with the previous behavior, and allow this comparison. I'd like to do that as a very last resort and try to fix Flutter first.

@stereotype441
Copy link
Member

FYI, some related bugs:

@sigmundch
Copy link
Member

@a-siva I see that your pull request was merged, is it OK to close this issue now?

@a-siva
Copy link
Contributor Author

a-siva commented Apr 11, 2019

Flutter code has been fixed.

@a-siva a-siva closed this as completed Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

4 participants