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

Dartboard differs from Dart VM in treatment of if(1) { ... } #1190

Closed
sethladd opened this issue Jan 17, 2012 · 6 comments
Closed

Dartboard differs from Dart VM in treatment of if(1) { ... } #1190

sethladd opened this issue Jan 17, 2012 · 6 comments
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue

Comments

@sethladd
Copy link
Contributor

Code:

main() {
  if (1) {
    print("I don't think this should work");
  }
}

In Dartboard, with NON-checked mode, the print statement is displayed. A warning is displayed: int is not assignable to bool. In Checked mode, it errors as expected. Example: http://try.dartlang.org/s/SC0o

In Dart VM via the Dart Editor, the print statement is NOT displayed.

@DartBot
Copy link

DartBot commented Jan 17, 2012

This comment was originally written by ngeoffray@google.com


Added Area-Compiler, Triaged labels.

@DartBot
Copy link

DartBot commented Jan 19, 2012

This comment was originally written by zundel@google.com


The spec says that any non-boolean value must be converted to a boolean using boolean conversion. Here's the def'n:

Boolean conversion maps any object o into a boolean defined as

(bool v){
          assert(v != null);
    return v === true;
}(o)

So it appears we need to change dartc code generation to add this logic to most conditional expressions, as even if type information is declared, at runtime a non-boolean type might be a part of an expression.

@DartBot
Copy link

DartBot commented Mar 8, 2012

This comment was originally written by molino....@gmail.com


Also with 'checked mode' this example display the print statement:

Code:
  
  var fullName;
  if (!fullName) {
    print("Please enter a full name");
  }

@ghost
Copy link

ghost commented Mar 8, 2012

  var fullName;
  if (!fullName) {
    print("Please enter a full name");
  }

The correct behavior of the code above is:

  • production mode: print text
  • checked mode: throw exception (type 'Null' is not assignable to type 'bool' of 'boolean expression')

@DartBot
Copy link

DartBot commented Mar 17, 2012

This comment was originally written by gcod...@chqrlie.org


What is the rationale for this dogmatic stance? Such a complete departure from commonly understood behaviour is so counter intuitive and error prone! Why not amend the boolean conversion semantics?

@DartBot
Copy link

DartBot commented Apr 3, 2012

This comment was originally written by zundel@google.com


The issue about the language definition has been brought up in other places. Since dartc no longer generates code, I'm closing this bug as obsolete.


Added WontFix label.

@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue and removed resolution-wont_fix labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue
Projects
None yet
Development

No branches or pull requests

3 participants