Skip to content
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

Null message error on build-time assert #47994

Closed
cmc5788 opened this issue Dec 21, 2021 · 0 comments
Closed

Null message error on build-time assert #47994

cmc5788 opened this issue Dec 21, 2021 · 0 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@cmc5788
Copy link

cmc5788 commented Dec 21, 2021

At runtime, including either an implicit or an explicit null assert message seems to behave correctly. In other words, both of these work as expected:

assert(false, null); // Failed assertion: ... 'false': is not true.
assert(false); // Failed assertion: ... 'false': is not true.

However, at build-time, asserts with an explicit null message will fail. I discovered this when I was building the following micro-library intended to make it easier for us to use build-time asserts;

https://github.com/cmc5788/global_assert#why-not-allow-an-assert-without-a-message
https://pub.dev/packages/global_assert

A minimal reproduction sample is as follows;

class BuildAssert {
  const BuildAssert(bool condition, [String? message])
      : assert(condition, message);
}

const _assert = BuildAssert(false);

void main() {}

Compiling this will fail with:

Context: Expected constant 'null' to be of type 'String', but was of type 'Null'.

  • Dart SDK Version (dart --version)
Dart SDK version: 2.15.0-268.18.beta (beta) (Wed Nov 17 11:39:23 2021 +0100) on "macos_x64"
@lrhn lrhn added area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Dec 22, 2021
@johnniwinther johnniwinther self-assigned this Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants