File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -2037,10 +2037,10 @@ export function compileCall(
2037
2037
checkArgsRequired ( operands , 1 , reportNode , compiler )
2038
2038
) return module . unreachable ( ) ;
2039
2039
let toType = typeArguments ! [ 0 ] ;
2040
- let arg0 = compiler . compileExpression ( operands [ 0 ] , toType ) ;
2040
+ let arg0 = compiler . compileExpression ( operands [ 0 ] , Type . auto ) ;
2041
2041
let fromType = compiler . currentType ;
2042
2042
compiler . currentType = toType ;
2043
- if ( fromType . size != toType . size ) {
2043
+ if ( ! fromType . isChangeableTo ( toType ) ) {
2044
2044
compiler . error (
2045
2045
DiagnosticCode . Type_0_cannot_be_changed_to_type_1 ,
2046
2046
reportNode . range , fromType . toString ( ) , toType . toString ( )
Original file line number Diff line number Diff line change @@ -280,6 +280,15 @@ export class Type {
280
280
return this . kind == target . kind ;
281
281
}
282
282
283
+ /** Tests if a value of this type can be changed to the target type using `changetype`. */
284
+ isChangeableTo ( target : Type ) : bool {
285
+ if ( this . is ( TypeFlags . INTEGER ) && target . is ( TypeFlags . INTEGER ) ) {
286
+ let size = this . size ;
287
+ return size == target . size && ( size >= 32 || this . is ( TypeFlags . SIGNED ) == target . is ( TypeFlags . SIGNED ) ) ;
288
+ }
289
+ return this . kind == target . kind ;
290
+ }
291
+
283
292
/** Determines the common denominator type of two types, if there is any. */
284
293
static commonDenominator ( left : Type , right : Type , signednessIsImportant : bool ) : Type | null {
285
294
if ( right . isAssignableTo ( left , signednessIsImportant ) ) return left ;
You can’t perform that action at this time.
0 commit comments