|
| 1 | +// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +// Tests that horizontal inference works properly when the invocation is an |
| 6 | +// extension member. This is an important corner case because the front end |
| 7 | +// adds an implicit `this` argument to extension members as part of the lowering |
| 8 | +// process. We need to make sure that the dependency tracking logic properly |
| 9 | +// accounts for this extra argument. |
| 10 | + |
| 11 | +// SharedOptions=--enable-experiment=inference-update-1 |
| 12 | + |
| 13 | +testLaterUnnamedParameter(int i) { |
| 14 | + i._laterUnnamedParameter(0, (x) { |
| 15 | + x; |
| 16 | + }); |
| 17 | +} |
| 18 | + |
| 19 | +/// This special case verifies that the implementations correctly associate the |
| 20 | +/// zeroth positional parameter with the corresponding argument (even if that |
| 21 | +/// argument isn't in the zeroth position at the call site). |
| 22 | +testLaterUnnamedParameterDependsOnNamedParameter(int i) { |
| 23 | + i._laterUnnamedParameterDependsOnNamedParameter(a: 0, (x) { |
| 24 | + x; |
| 25 | + }); |
| 26 | +} |
| 27 | + |
| 28 | +testEarlierUnnamedParameter(int i) { |
| 29 | + i._earlierUnnamedParameter((x) { |
| 30 | + x; |
| 31 | + }, 0); |
| 32 | +} |
| 33 | + |
| 34 | +testLaterNamedParameter(int i) { |
| 35 | + i._laterNamedParameter( |
| 36 | + a: 0, |
| 37 | + b: (x) { |
| 38 | + x; |
| 39 | + }); |
| 40 | +} |
| 41 | + |
| 42 | +testEarlierNamedParameter(int i) { |
| 43 | + i._earlierNamedParameter( |
| 44 | + a: (x) { |
| 45 | + x; |
| 46 | + }, |
| 47 | + b: 0); |
| 48 | +} |
| 49 | + |
| 50 | +/// This special case verifies that the implementations correctly associate the |
| 51 | +/// zeroth positional parameter with the corresponding argument (even if that |
| 52 | +/// argument isn't in the zeroth position at the call site). |
| 53 | +testEarlierNamedParameterDependsOnUnnamedParameter(int i) { |
| 54 | + i._earlierNamedParameterDependsOnUnnamedParameter(a: (x) { |
| 55 | + x; |
| 56 | + }, 0); |
| 57 | +} |
| 58 | + |
| 59 | +testPropagateToReturnType(int i) { |
| 60 | + i._propagateToReturnType(0, (x) => [x]); |
| 61 | +} |
| 62 | + |
| 63 | +// The test cases below exercise situations where there are multiple closures in |
| 64 | +// the invocation, and they need to be inferred in the right order. |
| 65 | + |
| 66 | +testClosureAsParameterType(int i) { |
| 67 | + i._closureAsParameterType(() => 0, (h) => [h()]) |
| 68 | + ; |
| 69 | +} |
| 70 | + |
| 71 | +testPropagateToEarlierClosure(int i) { |
| 72 | + i._propagateToEarlierClosure((x) => [x], () => 0) |
| 73 | + ; |
| 74 | +} |
| 75 | + |
| 76 | +testPropagateToLaterClosure(int i) { |
| 77 | + i._propagateToLaterClosure(() => 0, (x) => [x]) |
| 78 | + ; |
| 79 | +} |
| 80 | + |
| 81 | +testLongDependencyChain(int i) { |
| 82 | + i._longDependencyChain(() => [0], (x) => x.single, |
| 83 | + (y) => {y}) |
| 84 | + ; |
| 85 | +} |
| 86 | + |
| 87 | +testDependencyCycle(int i) { |
| 88 | + i._dependencyCycle((x) => [x], |
| 89 | + (y) => {y}) |
| 90 | + ; |
| 91 | +} |
| 92 | + |
| 93 | +testPropagateFromContravariantReturnType(int i) { |
| 94 | + i._propagateFromContravariantReturnType(() => (int i) {}, (x) => [x]) |
| 95 | + ; |
| 96 | +} |
| 97 | + |
| 98 | +testPropagateToContravariantParameterType(int i) { |
| 99 | + i._propagateToContravariantParameterType(() => 0, (x) => [x]) |
| 100 | + ; |
| 101 | +} |
| 102 | + |
| 103 | +testReturnTypeRefersToMultipleTypeVars(int i) { |
| 104 | + i._returnTypeRefersToMultipleTypeVars(() => {0: ''}, (k) { |
| 105 | + k; |
| 106 | + }, (v) { |
| 107 | + v; |
| 108 | + }); |
| 109 | +} |
| 110 | + |
| 111 | +testUnnecessaryDueToNoDependency(int i) { |
| 112 | + i._unnecessaryDueToNoDependency(() => 0, null); |
| 113 | +} |
| 114 | + |
| 115 | +testUnnecessaryDueToExplicitParameterTypeNamed(int i) { |
| 116 | + var a = i._unnecessaryDueToExplicitParameterTypeNamed(null, ({int? x, required y}) => (x ?? 0) + y); |
| 117 | + a; |
| 118 | +} |
| 119 | + |
| 120 | +testParenthesized(int i) { |
| 121 | + i._parenthesized(0, ((x) { |
| 122 | + x; |
| 123 | + })); |
| 124 | +} |
| 125 | + |
| 126 | +testParenthesizedNamed(int i) { |
| 127 | + i._parenthesizedNamed( |
| 128 | + a: 0, |
| 129 | + b: ((x) { |
| 130 | + x; |
| 131 | + })); |
| 132 | +} |
| 133 | + |
| 134 | +testParenthesizedTwice(int i) { |
| 135 | + i._parenthesizedTwice(0, (((x) { |
| 136 | + x; |
| 137 | + }))); |
| 138 | +} |
| 139 | + |
| 140 | +testParenthesizedTwiceNamed(int i) { |
| 141 | + i._parenthesizedTwiceNamed( |
| 142 | + a: 0, |
| 143 | + b: (((x) { |
| 144 | + x; |
| 145 | + }))); |
| 146 | +} |
| 147 | + |
| 148 | +extension on int { |
| 149 | + T _laterUnnamedParameter<T>(T x, void Function(T) y) => throw ''; |
| 150 | + void _laterUnnamedParameterDependsOnNamedParameter<T>(void Function(T) x, {required T a}) => throw ''; |
| 151 | + void _earlierUnnamedParameter<T>(void Function(T) x, T y) => throw ''; |
| 152 | + void _laterNamedParameter<T>({required T a, required void Function(T) b}) => throw ''; |
| 153 | + void _earlierNamedParameter<T>({required void Function(T) a, required T b}) => throw ''; |
| 154 | + void _earlierNamedParameterDependsOnUnnamedParameter<T>(T b, {required void Function(T) a}) => throw ''; |
| 155 | + U _propagateToReturnType<T, U>(T x, U Function(T) y) => throw ''; |
| 156 | + U _closureAsParameterType<T, U>(T x, U Function(T) y) => throw ''; |
| 157 | + U _propagateToEarlierClosure<T, U>(U Function(T) x, T Function() y) => throw ''; |
| 158 | + U _propagateToLaterClosure<T, U>(T Function() x, U Function(T) y) => throw ''; |
| 159 | + V _longDependencyChain<T, U, V>(T Function() x, U Function(T) y, V Function(U) z) => throw ''; |
| 160 | + Map<T, U> _dependencyCycle<T, U>(T Function(U) x, U Function(T) y) => throw ''; |
| 161 | + U _propagateFromContravariantReturnType<T, U>(void Function(T) Function() x, U Function(T) y) => throw ''; |
| 162 | + U _propagateToContravariantParameterType<T, U>(T Function() x, U Function(void Function(T)) y) => throw ''; |
| 163 | + void _returnTypeRefersToMultipleTypeVars<T, U>( |
| 164 | + Map<T, U> Function() x, void Function(T) y, void Function(U) z) => throw ''; |
| 165 | + T _unnecessaryDueToNoDependency<T>(T Function() x, T y) => throw ''; |
| 166 | + T _unnecessaryDueToExplicitParameterTypeNamed<T>(T x, T Function({required T x, required int y}) y) => throw ''; |
| 167 | + void _parenthesized<T>(T x, void Function(T) y) => throw ''; |
| 168 | + void _parenthesizedNamed<T>({required T a, required void Function(T) b}) => throw ''; |
| 169 | + void _parenthesizedTwice<T>(T x, void Function(T) y) => throw ''; |
| 170 | + void _parenthesizedTwiceNamed<T>({required T a, required void Function(T) b}) => throw ''; |
| 171 | +} |
| 172 | + |
| 173 | +main() {} |
0 commit comments