Skip to content

Update code example for Instantiation to Bound Algorithm #2679

@jmewes

Description

@jmewes

Observed

In the Dart language specification there the following code example for the section "Generics > Instantiation to Bound > The Instantiation to Bound Algorithm":

typedef Inv<X> = X Function(X);
class B<Y extends num, Z extends Inv<Y>> {}

B b; // The raw B means B<num, Inv<num>>.

(see 14efbe8/specification/dartLangSpec.tex#L8044-L8049)

This yields a not_initialized_non_nullable_variable error.

error

Expected

The variable b should have a nullable type, contain an instance of type B, or be declared within a function.

typedef Inv<X> = X Function(X);

class B<Y extends num, Z extends Inv<Y>> {
  Y? y;
  Z? z;
}

void main() {
  B b = B();
  assert(b.y is num?);
  assert(b.z is Inv<num>?);
}

Comment

In the example below there is a similar code snippet that shows an example for a compilation error. It might be useful to adapt this as well, so that it show the expected compilation error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThere is a mistake in the language specification or in an active document

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions