Skip to content

Instantly share code, notes, and snippets.

@leonsenft
leonsenft / main.dart
Last active June 28, 2018 06:20
TypeError due to lack of inference
typedef PathFunction = String Function([List<String> segment]);
PathFunction createPathFunction() {
// The type of this default list is not inferred from context.
// Typing the LHS or applying type arguments to the RHS fixes this.
return ([args = const []]) {
return '/${args.join('/')}';
};
}
@leonsenft
leonsenft / main.dart
Created January 31, 2020 18:33
Demonstrates that type inference is dependent on order of type parameters
class Value {}
class Renderer<T> {}
// When V is defined before R, type inference works in all cases.
class WorkingOrder<V extends Value, R extends Renderer<V>> {}
// When V is defined after R, type inference fails in some cases.
class BrokenOrder<R extends Renderer<V>, V extends Value> {}