@@ -5421,33 +5421,22 @@ export class Compiler extends DiagnosticEmitter {
5421
5421
if ( thisArg ) {
5422
5422
let parent = assert ( instance . parent ) ;
5423
5423
assert ( parent . kind == ElementKind . CLASS ) ;
5424
- if ( getExpressionId ( thisArg ) == ExpressionId . GetLocal ) {
5425
- flow . addScopedLocalAlias (
5426
- getGetLocalIndex ( thisArg ) ,
5427
- ( < Class > parent ) . type ,
5428
- "this"
5429
- ) ;
5430
- let parentBase = ( < Class > parent ) . base ;
5431
- if ( parentBase ) {
5432
- flow . addScopedLocalAlias (
5433
- getGetLocalIndex ( thisArg ) ,
5434
- parentBase . type ,
5435
- "super"
5436
- ) ;
5437
- }
5438
- } else {
5439
- let thisLocal = flow . addScopedLocal ( ( < Class > parent ) . type , "this" , false ) ;
5424
+ let thisType = assert ( instance . signature . thisType ) ;
5425
+ let classType = thisType . classReference ;
5426
+ let superType = classType
5427
+ ? classType . base
5428
+ ? classType . base . type
5429
+ : null
5430
+ : null ;
5431
+ if ( getExpressionId ( thisArg ) == ExpressionId . GetLocal ) { // reuse this var
5432
+ flow . addScopedLocalAlias ( getGetLocalIndex ( thisArg ) , thisType , "this" ) ;
5433
+ if ( superType ) flow . addScopedLocalAlias ( getGetLocalIndex ( thisArg ) , superType , "super" ) ;
5434
+ } else { // use a temp var
5435
+ let thisLocal = flow . addScopedLocal ( thisType , "this" , false ) ;
5440
5436
body . push (
5441
5437
module . createSetLocal ( thisLocal . index , thisArg )
5442
5438
) ;
5443
- let parentBase = ( < Class > parent ) . base ;
5444
- if ( parentBase ) {
5445
- flow . addScopedLocalAlias (
5446
- thisLocal . index ,
5447
- parentBase . type ,
5448
- "super"
5449
- ) ;
5450
- }
5439
+ if ( superType ) flow . addScopedLocalAlias ( thisLocal . index , superType , "super" ) ;
5451
5440
}
5452
5441
}
5453
5442
var parameterTypes = signature . parameterTypes ;
@@ -5895,7 +5884,7 @@ export class Compiler extends DiagnosticEmitter {
5895
5884
}
5896
5885
5897
5886
compileElementAccessExpression ( expression : ElementAccessExpression , contextualType : Type ) : ExpressionRef {
5898
- var target = this . resolver . resolveElementAccess ( expression , this . currentFunction ) ; // reports
5887
+ var target = this . resolver . resolveElementAccess ( expression , this . currentFunction , contextualType ) ; // reports
5899
5888
if ( ! target ) return this . module . createUnreachable ( ) ;
5900
5889
switch ( target . kind ) {
5901
5890
case ElementKind . CLASS : {
@@ -6003,7 +5992,7 @@ export class Compiler extends DiagnosticEmitter {
6003
5992
if ( currentFunction . is ( CommonFlags . INSTANCE ) ) {
6004
5993
let parent = assert ( currentFunction . parent ) ;
6005
5994
assert ( parent . kind == ElementKind . CLASS ) ;
6006
- let thisType = ( < Class > parent ) . type ;
5995
+ let thisType = assert ( currentFunction . signature . thisType ) ;
6007
5996
if ( currentFunction . is ( CommonFlags . CONSTRUCTOR ) ) {
6008
5997
if ( ! flow . is ( FlowFlags . ALLOCATES ) ) {
6009
5998
flow . set ( FlowFlags . ALLOCATES ) ;
@@ -6194,84 +6183,16 @@ export class Compiler extends DiagnosticEmitter {
6194
6183
intValue
6195
6184
) ;
6196
6185
}
6197
- switch ( contextualType . kind ) {
6198
-
6199
- // compile to contextualType if matching
6200
-
6201
- case TypeKind . I8 : {
6202
- if ( i64_is_i8 ( intValue ) ) return module . createI32 ( i64_low ( intValue ) ) ;
6203
- break ;
6204
- }
6205
- case TypeKind . U8 : {
6206
- if ( i64_is_u8 ( intValue ) ) return module . createI32 ( i64_low ( intValue ) ) ;
6207
- break ;
6208
- }
6209
- case TypeKind . I16 : {
6210
- if ( i64_is_i16 ( intValue ) ) return module . createI32 ( i64_low ( intValue ) ) ;
6211
- break ;
6212
- }
6213
- case TypeKind . U16 : {
6214
- if ( i64_is_u16 ( intValue ) ) return module . createI32 ( i64_low ( intValue ) ) ;
6215
- break ;
6216
- }
6217
- case TypeKind . I32 : {
6218
- if ( i64_is_i32 ( intValue ) ) return module . createI32 ( i64_low ( intValue ) ) ;
6219
- break ;
6220
- }
6221
- case TypeKind . U32 : {
6222
- if ( i64_is_u32 ( intValue ) ) return module . createI32 ( i64_low ( intValue ) ) ;
6223
- break ;
6224
- }
6225
- case TypeKind . BOOL : {
6226
- if ( i64_is_bool ( intValue ) ) return module . createI32 ( i64_low ( intValue ) ) ;
6227
- break ;
6228
- }
6229
- case TypeKind . ISIZE : {
6230
- if ( ! this . options . isWasm64 ) {
6231
- if ( i64_is_i32 ( intValue ) ) return module . createI32 ( i64_low ( intValue ) ) ;
6232
- break ;
6233
- }
6234
- return module . createI64 ( i64_low ( intValue ) , i64_high ( intValue ) ) ;
6235
- }
6236
- case TypeKind . USIZE : {
6237
- if ( ! this . options . isWasm64 ) {
6238
- if ( i64_is_u32 ( intValue ) ) return module . createI32 ( i64_low ( intValue ) ) ;
6239
- break ;
6240
- }
6241
- return module . createI64 ( i64_low ( intValue ) , i64_high ( intValue ) ) ;
6242
- }
6243
- case TypeKind . I64 :
6244
- case TypeKind . U64 : {
6245
- return module . createI64 ( i64_low ( intValue ) , i64_high ( intValue ) ) ;
6246
- }
6247
- case TypeKind . F32 : {
6248
- if ( i64_is_f32 ( intValue ) ) return module . createF32 ( i64_to_f32 ( intValue ) ) ;
6249
- break ;
6250
- }
6251
- case TypeKind . F64 : {
6252
- if ( i64_is_f64 ( intValue ) ) return module . createF64 ( i64_to_f64 ( intValue ) ) ;
6253
- break ;
6254
- }
6255
- case TypeKind . VOID : {
6256
- break ; // compiles to best fitting type below, being dropped
6257
- }
6258
- default : {
6259
- assert ( false ) ;
6260
- return module . createUnreachable ( ) ;
6261
- }
6262
- }
6263
-
6264
- // otherwise compile to best fitting native type
6265
-
6266
- if ( i64_is_i32 ( intValue ) ) {
6267
- this . currentType = Type . i32 ;
6268
- return module . createI32 ( i64_low ( intValue ) ) ;
6269
- } else if ( i64_is_u32 ( intValue ) ) {
6270
- this . currentType = Type . u32 ;
6271
- return module . createI32 ( i64_low ( intValue ) ) ;
6272
- } else {
6273
- this . currentType = Type . i64 ;
6274
- return module . createI64 ( i64_low ( intValue ) , i64_high ( intValue ) ) ;
6186
+ let type = this . resolver . determineIntegerLiteralType ( intValue , contextualType ) ;
6187
+ this . currentType = type ;
6188
+ switch ( type . kind ) {
6189
+ case TypeKind . ISIZE : if ( ! this . options . isWasm64 ) return module . createI32 ( i64_low ( intValue ) ) ;
6190
+ case TypeKind . I64 : return module . createI64 ( i64_low ( intValue ) , i64_high ( intValue ) ) ;
6191
+ case TypeKind . USIZE : if ( ! this . options . isWasm64 ) return module . createI32 ( i64_low ( intValue ) ) ;
6192
+ case TypeKind . U64 : return module . createI64 ( i64_low ( intValue ) , i64_high ( intValue ) ) ;
6193
+ case TypeKind . F32 : return module . createF32 ( i64_to_f32 ( intValue ) ) ;
6194
+ case TypeKind . F64 : return module . createF64 ( i64_to_f64 ( intValue ) ) ;
6195
+ default : return module . createI32 ( i64_low ( intValue ) ) ;
6275
6196
}
6276
6197
}
6277
6198
case LiteralKind . STRING : {
@@ -6749,7 +6670,7 @@ export class Compiler extends DiagnosticEmitter {
6749
6670
) : ExpressionRef {
6750
6671
var module = this . module ;
6751
6672
6752
- var target = this . resolver . resolvePropertyAccess ( propertyAccess , this . currentFunction ) ; // reports
6673
+ var target = this . resolver . resolvePropertyAccess ( propertyAccess , this . currentFunction , contextualType ) ; // reports
6753
6674
if ( ! target ) return module . createUnreachable ( ) ;
6754
6675
6755
6676
switch ( target . kind ) {
0 commit comments