Skip to content

Dart 2 changes to the language tour #677

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

Merged
merged 7 commits into from
Mar 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/misc/analyzer-2-results.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Analyzing lib, test...
error • The integer literal 34653465834652437659238476592374958739845729 can't be represented in 64 bits at lib/language_tour/built_in_types.dart:10:18 • integer_literal_out_of_range
# https://github.com/dart-lang/sdk/issues/32236 - flow analysis can't yet figure out that the variable is of type Person.
error • 'Object' doesn't extend 'SomeBaseClass' at lib/language_tour/generics/base_class.dart:43:21 • type_argument_not_matching_bounds
error • A value of type 'dynamic' can't be assigned to a variable of type 'Person' at lib/library_tour/core/hash_code.dart:25:21 • invalid_assignment
2 errors found.
19 changes: 0 additions & 19 deletions examples/misc/lib/language_tour/built_in_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ void miscDeclAnalyzedButNotTested() {
// #docregion integer-literals
int x = 1;
int hex = 0xDEADBEEF;
// ignore_for_file: 2, integer_literal_out_of_range
int bigInt = 34653465834652437659238476592374958739845729;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[No action necessary] We should document BigInt somewhere under "Libraries". I've added a bullet to our meta issue #637.

// #enddocregion integer-literals
}

Expand Down Expand Up @@ -59,23 +57,6 @@ void miscDeclAnalyzedButNotTested() {
// #enddocregion string-literals
}

{
// #docregion strictly-boolean
var name = 'Bob';
// #enddocregion strictly-boolean
/*
// #docregion strictly-boolean
if (name) {
// #enddocregion strictly-boolean
*/
if (name != null && name.isNotEmpty) {
// #docregion strictly-boolean
// Prints in JavaScript, not in Dart.
print('You have a name!');
}
// #enddocregion strictly-boolean
}

{
var c = true;
/*
Expand Down
20 changes: 0 additions & 20 deletions examples/misc/lib/language_tour/classes/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@ abstract class AbstractContainer {
}
// #enddocregion abstract

// #docregion extends
class SpecializedContainer extends AbstractContainer {
// Define constructors, fields, methods...

void updateChildren() {
// Provide an implementation, so the method is not abstract here...
}

// Abstract method causes a warning but
// doesn't prevent instantiation.
// #enddocregion extends
/*
// #docregion extends
void doSomething();
// #enddocregion extends
*/
// #docregion extends
}
// #enddocregion extends

class Comparable {}

class Location {}
Expand Down
6 changes: 6 additions & 0 deletions examples/misc/lib/language_tour/classes/point_alt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ class Point {
}
// #enddocregion initializer-list

// #docregion initializer-list-with-assert
Point.withAssert(this.x, this.y) : assert(x >= 0) {
print('In Point.withAssert(): ($x, $y)');
}
// #enddocregion initializer-list-with-assert

// #docregion constructor-long-way
}
19 changes: 14 additions & 5 deletions examples/misc/lib/language_tour/generics/base_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,32 @@ class Extender extends SomeBaseClass {
// Implementation goes here.
// #docregion
}
// #enddocregion

void main() {
// It's OK to use SomeBaseClass or any of its subclasses inside <>.
// #docregion SomeBaseClass-ok
var someBaseClassFoo = new Foo<SomeBaseClass>();
var extenderFoo = new Foo<Extender>();
// #enddocregion SomeBaseClass-ok

// It's also OK to use no <> at all.
// #docregion no-generic-arg-ok
var foo = new Foo();

// Specifying any non-SomeBaseClass type results in a warning and, in
// checked mode, a runtime error.
// var objectFoo = new Foo<Object>();
// #enddocregion
// #enddocregion no-generic-arg-ok

// Normal mode: Foo<SomeBaseClass>, Foo<Extender>, Foo<dynamic>, Foo<Object>
// print('$someBaseClassFoo, $extenderFoo, $foo, $objectFoo');

// Foo<SomeBaseClass>, Foo<Extender>, Foo<dynamic>
print('$someBaseClassFoo, $extenderFoo, $foo');
}

dynamic notTestedOnlyAnalyzed() {
// ignore_for_file: 2, type_argument_not_matching_bounds
// Specifying any non-SomeBaseClass type results in an error.
// #docregion Foo-Object-error
var foo = new Foo<Object>(); //!analysis-issue
// #enddocregion Foo-Object-error
return foo;
}
6 changes: 6 additions & 0 deletions examples/misc/lib/language_tour/variables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ void miscDeclAnalyzedButNotTested() {
// #enddocregion var-decl
}

{
// #docregion type-decl
dynamic name = 'Bob';
// #enddocregion type-decl
}

{
// #docregion static-types
String name = 'Bob';
Expand Down
4 changes: 2 additions & 2 deletions examples/misc/test/language_tour/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ void main() {
test('basic', () {
// #docregion
// Define a function.
printNumber(num aNumber) {
printInteger(int aNumber) {
print('The number is $aNumber.'); // Print to console.
}

// This is where the app starts executing.
main() {
var number = 42; // Declare and initialize a variable.
printNumber(number); // Call a function.
printInteger(number); // Call a function.
}

// #enddocregion
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/test/language_tour/generics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void assignIntToStringList() {
// #docregion why-generics
var names = new List<String>();
names.addAll(['Seth', 'Kathy', 'Lars']);
names.add(42); // Fails in checked mode (succeeds in production mode).
names.add(42); // Error
// #enddocregion why-generics
}

Expand Down
1 change: 0 additions & 1 deletion examples/misc/test/language_tour/variables_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ void main() {
// #docregion var-null-init
int lineCount;
assert(lineCount == null);
// Variables (even if they will be numbers) are initially null.
// #enddocregion var-null-init
});
}
Loading