@@ -102,14 +102,14 @@ else if ( to == byte.class ) {
102
102
}
103
103
else if ( isIntegralTypePrimitive ( to ) ) {
104
104
return from == byte .class
105
- || isIntegralTypePrimitive ( from )
105
+ || isCompatibleIntegralTypePrimitive ( to , from )
106
106
// this would for sure cause loss of precision
107
107
|| isFloatingTypePrimitive ( from );
108
108
}
109
109
else if ( isFloatingTypePrimitive ( to ) ) {
110
110
return from == byte .class
111
111
|| isIntegralTypePrimitive ( from )
112
- || isFloatingTypePrimitive ( from );
112
+ || isCompatibleFloatingTypePrimitive ( to , from );
113
113
}
114
114
115
115
return false ;
@@ -133,6 +133,22 @@ private static boolean isIntegralTypePrimitive(Class potentialIntegral) {
133
133
|| potentialIntegral == long .class ;
134
134
}
135
135
136
+ private static boolean isCompatibleIntegralTypePrimitive (Class to , Class from ) {
137
+ assert isIntegralTypePrimitive ( to );
138
+ assert from .isPrimitive ();
139
+
140
+ if ( to == short .class ) {
141
+ return from == short .class ;
142
+ }
143
+ else if ( to == int .class ) {
144
+ return from == short .class
145
+ || from == int .class ;
146
+ }
147
+ else {
148
+ return isIntegralTypePrimitive ( from );
149
+ }
150
+ }
151
+
136
152
public static boolean isFloatingType (Class potentialFloating ) {
137
153
if ( potentialFloating .isPrimitive () ) {
138
154
return isFloatingTypePrimitive ( potentialFloating );
@@ -150,6 +166,18 @@ private static boolean isFloatingTypePrimitive(Class potentialFloating) {
150
166
|| potentialFloating == double .class ;
151
167
}
152
168
169
+ private static boolean isCompatibleFloatingTypePrimitive (Class to , Class from ) {
170
+ assert isFloatingTypePrimitive ( to );
171
+ assert from .isPrimitive ();
172
+
173
+ if ( to == float .class ) {
174
+ return from == float .class ;
175
+ }
176
+ else {
177
+ return isFloatingTypePrimitive ( from );
178
+ }
179
+ }
180
+
153
181
public static boolean areAssignmentCompatible (
154
182
JavaType to ,
155
183
JavaType from ) {
0 commit comments