|
20 | 20 | import org.eclipse.n4js.n4JS.Expression;
|
21 | 21 | import org.eclipse.n4js.n4JS.FormalParameter;
|
22 | 22 | import org.eclipse.n4js.n4JS.FunctionExpression;
|
| 23 | +import org.eclipse.n4js.n4JS.N4JSASTUtils; |
23 | 24 | import org.eclipse.n4js.n4JS.ObjectLiteral;
|
24 | 25 | import org.eclipse.n4js.n4JS.ParameterizedCallExpression;
|
25 | 26 | import org.eclipse.n4js.n4JS.PropertyAssignment;
|
26 | 27 | import org.eclipse.n4js.n4JS.PropertyMethodDeclaration;
|
27 | 28 | import org.eclipse.n4js.n4JS.RelationalExpression;
|
| 29 | +import org.eclipse.n4js.n4JS.YieldExpression; |
28 | 30 | import org.eclipse.n4js.ts.typeRefs.TypeRef;
|
29 | 31 | import org.eclipse.n4js.ts.types.TypableElement;
|
30 | 32 | import org.eclipse.n4js.ts.types.util.Variance;
|
@@ -161,14 +163,14 @@ void inferType(RuleEnvironment G, Expression rootPoly, ASTMetaInfoCache cache) {
|
161 | 163 | infCtx.addConstraint(TypeConstraint.FALSE);
|
162 | 164 | }
|
163 | 165 |
|
164 |
| - TypeRef expectedTypeOfPoly = destructureHelper.calculateExpectedType(rootPoly, G, infCtx); |
| 166 | + TypeRef expectedTypeByLiteralStructure = destructureHelper.calculateExpectedType(rootPoly, G, infCtx); |
165 | 167 | // we have to pass the expected type to the #getType() method, so retrieve it first
|
166 | 168 | // (until the expectedType judgment is integrated into AST traversal, we have to invoke this judgment here;
|
167 | 169 | // in case of not-well-behaving expectedType rules, we use 'null' as expected type, i.e. no expectation)
|
168 | 170 | // TODO integrate expectedType judgment into AST traversal and remove #isProblematicCaseOfExpectedType()
|
169 | 171 | TypeRef expectedTypeRef = null;
|
170 |
| - if (expectedTypeOfPoly != null) { |
171 |
| - expectedTypeRef = expectedTypeOfPoly; |
| 172 | + if (expectedTypeByLiteralStructure != null) { |
| 173 | + expectedTypeRef = expectedTypeByLiteralStructure; |
172 | 174 | } else if (!isProblematicCaseOfExpectedType(rootPoly)) {
|
173 | 175 | expectedTypeRef = ts.expectedType(G, rootPoly.eContainer(), rootPoly);
|
174 | 176 | }
|
@@ -261,7 +263,16 @@ protected TypeRef processExpr(RuleEnvironment G, Expression expr, TypeRef expect
|
261 | 263 | * Returns true if we are not allowed to ask for the expected type of 'node', because this would lead to illegal
|
262 | 264 | * forward references (temporary).
|
263 | 265 | */
|
264 |
| - private boolean isProblematicCaseOfExpectedType(EObject node) { |
265 |
| - return node != null && node.eContainer() instanceof RelationalExpression; |
| 266 | + private boolean isProblematicCaseOfExpectedType(Expression node) { |
| 267 | + if (node != null) { |
| 268 | + EObject parent = N4JSASTUtils.skipParenExpressionUpward(node.eContainer()); |
| 269 | + if (parent instanceof RelationalExpression) { |
| 270 | + return true; |
| 271 | + } |
| 272 | + if (parent instanceof YieldExpression) { |
| 273 | + return true; |
| 274 | + } |
| 275 | + } |
| 276 | + return false; |
266 | 277 | }
|
267 | 278 | }
|
0 commit comments