-
Notifications
You must be signed in to change notification settings - Fork 147
Error in demo code (on http://www.dartlang.org/) #812
Comments
From [email protected] on January 08, 2014 19:28:10 Status: Triaged |
From [email protected] on January 08, 2014 21:25:39 Owner: [email protected] |
From [email protected] on January 09, 2014 02:09:50 I do not see any error in the code. What is the problem? |
From [email protected] on January 09, 2014 04:58:56 Thanks for looking. If code is to make any sense it should be:
The test as is:
which makes the second test useless! |
From [email protected] on January 09, 2014 14:14:59 I am afraid that you have some fundamental misunderstanding. The code correctly checks whether n is at least 4 and at most 20, and neither condition is redundant. On the other hand, the condition “4 >= n && n <= 20” which you wrote in comment #4 is equivalent to “n <= 4”, and with that change, the program would throw ArgumentError because the constructor is called with n == 12. |
From [email protected] on January 09, 2014 14:50:34 You are right:
generates confusion, this code is clearer:
at least for me :( |
From [email protected] on February 06, 2014 11:01:42 Status: AsDesigned |
From [email protected] on January 09, 2014 04:13:32
What code is the problem?
this line:
in this code:
class Die { // Define a class.
static Random shaker = new Random(); // Define a class variable.
int sides, value; // Define instance variables.
String toString() => '$value'; // Define a method using shorthand syntax.
Die({int n: 6}) { // Define a constructor.
if (4 <= n && n <= 20) {
sides = n;
} else {
throw new ArgumentError(/* */); // Support for errors and exceptions.
}
}
int roll() { // Define an instance method.
return value = shaker.nextInt(sides); // Get a random number.
}
}
What is the expected line?
Original issue: http://code.google.com/p/dart/issues/detail?id=15981
The text was updated successfully, but these errors were encountered: