Phani Rithvij
Phani Rithvij

Reputation: 4487

why is dart's assert method is not working?

Dart's assert function is not working for me for some reason.

It wasn't firing on my system

Dart VM version: 2.7.0 (Fri Dec 6 16:26:51 2019 +0100) on "windows_x64"

It isn't working on dartpad aswell.

Please look at this dartpad https://dartpad.dev/5352f91de86a0b3c58fdf6a8fb64a081.

image

Upvotes: 3

Views: 1646

Answers (4)

Sam7919
Sam7919

Reputation: 631

If you are running brief Dart programs often from the command line to test ideas, it's worth adding the following line to your .bash_profile, .zshrc:

alias dart="dart --enable-asserts"

or similar for other shells.

Upvotes: 2

assert is not working on dartpad.dev either replit.com. I test it on 13 Oct 2021. So I used IntelliJ IDEA to work with assert and its working fine.

Upvotes: 0

Phani Rithvij
Phani Rithvij

Reputation: 4487

This wasn't specific to dartpad as it wasn't running on my machine as well on dart 2.7.0. I was able to run it with the flag --enable-asserts

dart --enable-asserts lib\main.dart

Note:

The flag must be passed as dart --enable-asserts lib\main.dart but not dart lib\main.dart --enable-asserts as the second approach implies this flag is meant for lib\main.dart and not dart.

Upvotes: 7

Mattia
Mattia

Reputation: 6524

It appears that assert statements are disable in dartpad since July 2019, you can check the GitHub issue here https://github.com/dart-lang/dart-pad/issues/310#issuecomment-514068279

Upvotes: 5

Related Questions