diff options
author | Stephan Herrmann | 2019-01-24 21:10:30 +0000 |
---|---|---|
committer | Stephan Herrmann | 2019-01-25 22:15:51 +0000 |
commit | 680c3339c41b939780173cfeba052235d9bf3d17 (patch) | |
tree | 995b1938a0c67b136ef6e0ebc128b95978134e4b /org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java | |
parent | e2c0af9a4f7c8c426838c5b2719daa2ef6f900be (diff) | |
download | eclipse.jdt.core-680c3339c41b939780173cfeba052235d9bf3d17.tar.gz eclipse.jdt.core-680c3339c41b939780173cfeba052235d9bf3d17.tar.xz eclipse.jdt.core-680c3339c41b939780173cfeba052235d9bf3d17.zip |
(bogusly called)
Change-Id: I603377666c4f8360b885055774176409176f3442
Diffstat (limited to 'org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java')
-rw-r--r-- | org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java | 102 |
1 files changed, 61 insertions, 41 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java index 7153c3e849..776824ae83 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java @@ -33,6 +33,7 @@ import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.codegen.CodeStream; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.impl.Constant; +import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; @@ -286,50 +287,69 @@ public class SwitchExpression extends SwitchStatement implements IPolyExpression @Override public TypeBinding resolveType(BlockScope upperScope) { try { - this.constant = Constant.NotAConstant; - - // tag break statements and (alongwih in the same pass) collect the result expressions - collectResultExpressions(); - - resolve(upperScope); - - if (this.statements == null || this.statements.length == 0) { - // Report Error JLS 12 15.29.1 The switch block must not be empty. - upperScope.problemReporter().switchExpressionEmptySwitchBlock(this); - return null; - } - - int resultExpressionsCount = this.resultExpressions != null ? this.resultExpressions.size() : 0; - if (resultExpressionsCount == 0) { - // Report Error JLS 12 15.29.1 - // It is a compile-time error if a switch expression has no result expressions. - upperScope.problemReporter().switchExpressionNoResultExpressions(this); - return null; - } - //A switch expression is a poly expression if it appears in an assignment context or an invocation context (5.2, 5.3). - //Otherwise, it is a standalone expression. - if (this.expressionContext == ASSIGNMENT_CONTEXT || this.expressionContext == INVOCATION_CONTEXT) { - for (Expression e : this.resultExpressions) { - //Where a poly switch expression appears in a context of a particular kind with target type T, - //its result expressions similarly appear in a context of the same kind with target type T. - e.setExpressionContext(this.expressionContext); - e.setExpectedType(this.expectedType); + int resultExpressionsCount; + if (this.constant != Constant.NotAConstant) { + this.constant = Constant.NotAConstant; + + // tag break statements and (alongwih in the same pass) collect the result expressions + collectResultExpressions(); + + // A switch expression is a poly expression if it appears in an assignment context or an invocation context (5.2, 5.3). + // Otherwise, it is a standalone expression. + if (this.expressionContext == ASSIGNMENT_CONTEXT || this.expressionContext == INVOCATION_CONTEXT) { + for (Expression e : this.resultExpressions) { + //Where a poly switch expression appears in a context of a particular kind with target type T, + //its result expressions similarly appear in a context of the same kind with target type T. + e.setExpressionContext(this.expressionContext); + e.setExpectedType(this.expectedType); + } } - } - - if (this.originalValueResultExpressionTypes == null) { - this.originalValueResultExpressionTypes = new TypeBinding[resultExpressionsCount]; - this.finalValueResultExpressionTypes = new TypeBinding[resultExpressionsCount]; - for (int i = 0; i < resultExpressionsCount; ++i) { - this.finalValueResultExpressionTypes[i] = this.originalValueResultExpressionTypes[i] = - this.resultExpressions.get(i).resolvedType; + + resolve(upperScope); + + if (this.statements == null || this.statements.length == 0) { + // Report Error JLS 12 15.29.1 The switch block must not be empty. + upperScope.problemReporter().switchExpressionEmptySwitchBlock(this); + return null; } - } - if (isPolyExpression()) { //The type of a poly switch expression is the same as its target type. - if (this.expectedType == null || !this.expectedType.isProperType(true)) { - return new PolyTypeBinding(this); + + resultExpressionsCount = this.resultExpressions != null ? this.resultExpressions.size() : 0; + if (resultExpressionsCount == 0) { + // Report Error JLS 12 15.29.1 + // It is a compile-time error if a switch expression has no result expressions. + upperScope.problemReporter().switchExpressionNoResultExpressions(this); + return null; + } + + if (this.originalValueResultExpressionTypes == null) { + this.originalValueResultExpressionTypes = new TypeBinding[resultExpressionsCount]; + this.finalValueResultExpressionTypes = new TypeBinding[resultExpressionsCount]; + for (int i = 0; i < resultExpressionsCount; ++i) { + this.finalValueResultExpressionTypes[i] = this.originalValueResultExpressionTypes[i] = + this.resultExpressions.get(i).resolvedType; + } + } + if (isPolyExpression()) { //The type of a poly switch expression is the same as its target type. + if (this.expectedType == null || !this.expectedType.isProperType(true)) { + return new PolyTypeBinding(this); + } + return this.resolvedType = computeConversions(this.scope, this.expectedType) ? this.expectedType : null; + } + // fall through + } else { + // re-resolving of poly expression: + resultExpressionsCount = this.resultExpressions != null ? this.resultExpressions.size() : 0; + for (int i = 0; i < resultExpressionsCount; i++) { + Expression resultExpr = this.resultExpressions.get(i); + if (resultExpr.resolvedType == null || resultExpr.resolvedType.kind() == Binding.POLY_TYPE) { + this.finalValueResultExpressionTypes[i] = this.originalValueResultExpressionTypes[i] = + resultExpr.resolveTypeExpecting(upperScope, this.expectedType); + } + if (resultExpr.resolvedType == null || !resultExpr.resolvedType.isValidBinding()) + return this.resolvedType = null; } - return this.resolvedType = computeConversions(this.scope, this.expectedType) ? this.expectedType : null; + this.resolvedType = computeConversions(this.scope, this.expectedType) ? this.expectedType : null; + // fall through } if (resultExpressionsCount == 1) |