-
Notifications
You must be signed in to change notification settings - Fork 317
/
CompilerBug2351Test.xtend
161 lines (146 loc) · 3.75 KB
/
CompilerBug2351Test.xtend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*******************************************************************************
* Copyright (c) 2024 Sebastian Zarnekow (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtend.core.tests.compiler
import org.junit.Test
/**
* @author Sebastian - Initial contribution and API
*/
class CompilerBug2351Test extends AbstractXtendCompilerTest {
@Test def void test_01() {
assertCompilesTo(
'''
package p
import java.math.BigDecimal
class C {
def Object m(int i) {
val r = switch(i) {
case 1: 1.0 // double
case 2: 1.0bd // BigDecimal
default: weird("")
}
return r
}
private def <T> T weird(Object object) {
return null;
}
}
''',
'''
package p;
import java.math.BigDecimal;
@SuppressWarnings("all")
public class C {
public Object m(final int i) {
Object _switchResult = null;
switch (i) {
case 1:
_switchResult = Double.valueOf(1.0);
break;
case 2:
_switchResult = new BigDecimal("1.0");
break;
default:
_switchResult = this.<Object>weird("");
break;
}
final Object r = _switchResult;
return r;
}
private <T extends Object> T weird(final Object object) {
return null;
}
}
'''
)
}
@Test def void test_02() {
assertCompilesTo(
'''
package p
import java.math.BigDecimal
class C {
def void m() {
val s1 = switch 45 { // int
case 2: 1
case 3: 3.0
case 78: exit('.')
case 4: 4.0 / 5.0
default: 6
}
val s2 = switch 45 { // Number
case 78: exit('.')
case 2: 1
case 3: 3.0
case 4: 4.0/5.0
default: 6
}
s1.toString
s2.toString
}
def <T> T exit(String message) {
throw new UnsupportedOperationException(message)
}
}
''',
'''
package p;
@SuppressWarnings("all")
public class C {
public void m() {
Number _switchResult = null;
final int _switchValue = 45;
switch (_switchValue) {
case 2:
_switchResult = Integer.valueOf(1);
break;
case 3:
_switchResult = Double.valueOf(3.0);
break;
case 78:
_switchResult = ((Number)this.<Number>exit("."));
break;
case 4:
_switchResult = Double.valueOf((4.0 / 5.0));
break;
default:
_switchResult = Integer.valueOf(6);
break;
}
final Number s1 = ((Number)_switchResult);
Number _switchResult_1 = null;
final int _switchValue_1 = 45;
switch (_switchValue_1) {
case 78:
_switchResult_1 = ((Number)this.<Number>exit("."));
break;
case 2:
_switchResult_1 = Integer.valueOf(1);
break;
case 3:
_switchResult_1 = Double.valueOf(3.0);
break;
case 4:
_switchResult_1 = Double.valueOf((4.0 / 5.0));
break;
default:
_switchResult_1 = Integer.valueOf(6);
break;
}
final Number s2 = ((Number)_switchResult_1);
s1.toString();
s2.toString();
}
public <T extends Object> T exit(final String message) {
throw new UnsupportedOperationException(message);
}
}
'''
)
}
}