|
14 | 14 | package org.eclipse.jdt.internal.compiler.ast;
|
15 | 15 |
|
16 | 16 | import org.eclipse.jdt.internal.compiler.ast.Pattern.PrimitiveConversionRoute;
|
| 17 | +import org.eclipse.jdt.internal.compiler.codegen.BranchLabel; |
17 | 18 | import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
|
18 | 19 | import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
|
19 | 20 | import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
|
@@ -52,11 +53,38 @@ default void generateTypeCheck(TypeBinding providedType, TypeReference expectedT
|
52 | 53 | TypeBinding boxType = scope.environment().computeBoxingType(expectedTypeRef.resolvedType);
|
53 | 54 | codeStream.instance_of(expectedTypeRef, boxType);
|
54 | 55 | }
|
55 |
| - case UNBOXING_CONVERSION, |
56 |
| - UNBOXING_AND_WIDENING_PRIMITIVE_CONVERSION -> { |
| 56 | + case UNBOXING_CONVERSION -> { |
57 | 57 | codeStream.instance_of(scope.getJavaLangObject());
|
58 | 58 | setPatternIsTotalType();
|
59 | 59 | }
|
| 60 | + case UNBOXING_AND_WIDENING_PRIMITIVE_CONVERSION -> { |
| 61 | + codeStream.dup(); |
| 62 | + codeStream.instance_of(providedType); |
| 63 | + BranchLabel iLabel = new BranchLabel(codeStream); |
| 64 | + BranchLabel postCheck = new BranchLabel(codeStream); |
| 65 | + |
| 66 | + codeStream.ifne(iLabel); |
| 67 | + codeStream.pop(); |
| 68 | + codeStream.iconst_0(); |
| 69 | + codeStream.goto_(postCheck); |
| 70 | + |
| 71 | + iLabel.place(); |
| 72 | + codeStream.checkcast(providedType); |
| 73 | + TypeBinding unboxedType = scope.environment().computeBoxingType(providedType); |
| 74 | + codeStream.generateUnboxingConversion(unboxedType.id); |
| 75 | + int expectedTypeId = expectedTypeRef.resolvedType.id; |
| 76 | + int unboxedProvidedTypeId = unboxedType.id; |
| 77 | + if (BaseTypeBinding.isExactWidening(expectedTypeId, unboxedProvidedTypeId)) { |
| 78 | + codeStream.pop(); |
| 79 | + codeStream.iconst_1(); |
| 80 | + } else { |
| 81 | + codeStream.invokeExactConversionsSupport(BaseTypeBinding.getRightToLeft(expectedTypeId, unboxedProvidedTypeId)); |
| 82 | + } |
| 83 | + |
| 84 | + codeStream.goto_(postCheck); |
| 85 | + postCheck.place(); |
| 86 | + setPatternIsTotalType(); |
| 87 | + } |
60 | 88 | case NO_CONVERSION_ROUTE -> {
|
61 | 89 | codeStream.instance_of(expectedTypeRef, expectedTypeRef.resolvedType);
|
62 | 90 | break;
|
|
0 commit comments