Skip to content

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

Closed

Description

@a-siva

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;
  ..................
  ..................
}

Activity

  1. added this to the Dart 2.3 milestone on Apr 11, 2019
  2. a-siva commented on Apr 11, 2019

    @a-siva
    ContributorAuthor

    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'
    
    
  3. added
    P1A high priority bug; for example, a single project is unusable or has many test failures
    on Apr 11, 2019
  4. kmillikin commented on Apr 11, 2019

    @kmillikin

    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

  5. kmillikin commented on Apr 11, 2019

    @kmillikin

    This is really a duplicate of #26980.

  6. kmillikin commented on Apr 11, 2019

    @kmillikin

    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.

  7. stereotype441 commented on Apr 11, 2019

    @stereotype441
    Member

    FYI, some related bugs:

  8. sigmundch commented on Apr 11, 2019

    @sigmundch
    Member

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

  9. a-siva commented on Apr 11, 2019

    @a-siva
    ContributorAuthor

    Flutter code has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1A high priority bug; for example, a single project is unusable or has many test failureslegacy-area-front-endLegacy: Use area-dart-model instead.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions