Skip to content

Commit 941b0e1

Browse files
authored
fix: Update this and return type in generated child class constructor (#2635)
1 parent e22a599 commit 941b0e1

File tree

4 files changed

+332
-96
lines changed

4 files changed

+332
-96
lines changed

src/compiler.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8695,7 +8695,14 @@ export class Compiler extends DiagnosticEmitter {
86958695
(<FunctionDeclaration>baseCtor.declaration).clone()
86968696
),
86978697
null,
8698-
baseCtor.signature,
8698+
Signature.create(
8699+
this.program,
8700+
baseCtor.signature.parameterTypes,
8701+
classInstance.type,
8702+
classInstance.type,
8703+
baseCtor.signature.requiredParameters,
8704+
baseCtor.signature.hasRest
8705+
),
86998706
contextualTypeArguments
87008707
);
87018708

tests/compiler/constructor.debug.wat

Lines changed: 157 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
(global $constructor/ctorConditionallyReturnsThis (mut i32) (i32.const 0))
3737
(global $constructor/ctorFieldInitOrder (mut i32) (i32.const 0))
3838
(global $~lib/rt/__rtti_base i32 (i32.const 464))
39-
(global $~lib/memory/__data_end i32 (i32.const 528))
40-
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 33296))
41-
(global $~lib/memory/__heap_base i32 (i32.const 33296))
39+
(global $~lib/memory/__data_end i32 (i32.const 532))
40+
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 33300))
41+
(global $~lib/memory/__heap_base i32 (i32.const 33300))
4242
(memory $0 1)
4343
(data (i32.const 12) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00(\00\00\00A\00l\00l\00o\00c\00a\00t\00i\00o\00n\00 \00t\00o\00o\00 \00l\00a\00r\00g\00e\00\00\00\00\00")
4444
(data (i32.const 76) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00 \00\00\00~\00l\00i\00b\00/\00r\00t\00/\00i\00t\00c\00m\00s\00.\00t\00s\00\00\00\00\00\00\00\00\00\00\00\00\00")
@@ -49,7 +49,7 @@
4949
(data (i32.const 320) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
5050
(data (i32.const 348) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00t\00l\00s\00f\00.\00t\00s\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
5151
(data (i32.const 412) ",\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\1c\00\00\00c\00o\00n\00s\00t\00r\00u\00c\00t\00o\00r\00.\00t\00s\00")
52-
(data (i32.const 464) "\0f\00\00\00 \00\00\00 \00\00\00 \00\00\00\00\00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00")
52+
(data (i32.const 464) "\10\00\00\00 \00\00\00 \00\00\00 \00\00\00\00\00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00 \00\00\00")
5353
(table $0 1 1 funcref)
5454
(elem $0 (i32.const 1))
5555
(export "memory" (memory $0))
@@ -2276,6 +2276,24 @@
22762276
i32.const 0
22772277
return
22782278
)
2279+
(func $constructor/CtorFieldInitWithoutConstructor#set:a (param $this i32) (param $a i32)
2280+
local.get $this
2281+
local.get $a
2282+
i32.store $0
2283+
)
2284+
(func $constructor/CtorFieldInitWithoutConstructor#get:a (param $this i32) (result i32)
2285+
local.get $this
2286+
i32.load $0
2287+
)
2288+
(func $constructor/CtorFieldInitWithoutConstructor#set:b (param $this i32) (param $b i32)
2289+
local.get $this
2290+
local.get $b
2291+
i32.store $0 offset=4
2292+
)
2293+
(func $constructor/CtorFieldInitWithoutConstructor#get:b (param $this i32) (result i32)
2294+
local.get $this
2295+
i32.load $0 offset=4
2296+
)
22792297
(func $constructor/CtorFieldInitOrder#get:a (param $this i32) (result i32)
22802298
local.get $this
22812299
i32.load $0 offset=4
@@ -2409,35 +2427,38 @@
24092427
(func $~lib/rt/__visit_members (param $0 i32) (param $1 i32)
24102428
block $invalid
24112429
block $constructor/CtorFieldInitOrder
2412-
block $constructor/CtorConditionallyReturnsThis
2413-
block $constructor/CtorConditionallyReturns
2414-
block $constructor/CtorReturns
2415-
block $constructor/JustFieldNoInit
2416-
block $constructor/JustFieldInit
2417-
block $constructor/None
2418-
block $constructor/EmptyCtorWithFieldAccess
2419-
block $constructor/EmptyCtorWithFieldNoInit
2420-
block $constructor/EmptyCtorWithFieldInit
2421-
block $constructor/EmptyCtor
2422-
block $~lib/arraybuffer/ArrayBufferView
2423-
block $~lib/string/String
2424-
block $~lib/arraybuffer/ArrayBuffer
2425-
block $~lib/object/Object
2426-
local.get $0
2427-
i32.const 8
2428-
i32.sub
2429-
i32.load $0
2430-
br_table $~lib/object/Object $~lib/arraybuffer/ArrayBuffer $~lib/string/String $~lib/arraybuffer/ArrayBufferView $constructor/EmptyCtor $constructor/EmptyCtorWithFieldInit $constructor/EmptyCtorWithFieldNoInit $constructor/EmptyCtorWithFieldAccess $constructor/None $constructor/JustFieldInit $constructor/JustFieldNoInit $constructor/CtorReturns $constructor/CtorConditionallyReturns $constructor/CtorConditionallyReturnsThis $constructor/CtorFieldInitOrder $invalid
2430+
block $constructor/CtorFieldInitWithoutConstructor
2431+
block $constructor/CtorConditionallyReturnsThis
2432+
block $constructor/CtorConditionallyReturns
2433+
block $constructor/CtorReturns
2434+
block $constructor/JustFieldNoInit
2435+
block $constructor/JustFieldInit
2436+
block $constructor/None
2437+
block $constructor/EmptyCtorWithFieldAccess
2438+
block $constructor/EmptyCtorWithFieldNoInit
2439+
block $constructor/EmptyCtorWithFieldInit
2440+
block $constructor/EmptyCtor
2441+
block $~lib/arraybuffer/ArrayBufferView
2442+
block $~lib/string/String
2443+
block $~lib/arraybuffer/ArrayBuffer
2444+
block $~lib/object/Object
2445+
local.get $0
2446+
i32.const 8
2447+
i32.sub
2448+
i32.load $0
2449+
br_table $~lib/object/Object $~lib/arraybuffer/ArrayBuffer $~lib/string/String $~lib/arraybuffer/ArrayBufferView $constructor/EmptyCtor $constructor/EmptyCtorWithFieldInit $constructor/EmptyCtorWithFieldNoInit $constructor/EmptyCtorWithFieldAccess $constructor/None $constructor/JustFieldInit $constructor/JustFieldNoInit $constructor/CtorReturns $constructor/CtorConditionallyReturns $constructor/CtorConditionallyReturnsThis $constructor/CtorFieldInitWithoutConstructor $constructor/CtorFieldInitOrder $invalid
2450+
end
2451+
return
24312452
end
24322453
return
24332454
end
24342455
return
24352456
end
2457+
local.get $0
2458+
local.get $1
2459+
call $~lib/arraybuffer/ArrayBufferView~visit
24362460
return
24372461
end
2438-
local.get $0
2439-
local.get $1
2440-
call $~lib/arraybuffer/ArrayBufferView~visit
24412462
return
24422463
end
24432464
return
@@ -2726,6 +2747,69 @@
27262747
global.set $~lib/memory/__stack_pointer
27272748
local.get $1
27282749
)
2750+
(func $constructor/CtorFieldInitWithoutConstructor#constructor (param $this i32) (result i32)
2751+
(local $1 i32)
2752+
global.get $~lib/memory/__stack_pointer
2753+
i32.const 12
2754+
i32.sub
2755+
global.set $~lib/memory/__stack_pointer
2756+
call $~stack_check
2757+
global.get $~lib/memory/__stack_pointer
2758+
i64.const 0
2759+
i64.store $0
2760+
global.get $~lib/memory/__stack_pointer
2761+
i32.const 0
2762+
i32.store $0 offset=8
2763+
local.get $this
2764+
i32.eqz
2765+
if
2766+
global.get $~lib/memory/__stack_pointer
2767+
i32.const 8
2768+
i32.const 14
2769+
call $~lib/rt/itcms/__new
2770+
local.tee $this
2771+
i32.store $0
2772+
end
2773+
global.get $~lib/memory/__stack_pointer
2774+
local.get $this
2775+
local.set $1
2776+
global.get $~lib/memory/__stack_pointer
2777+
local.get $1
2778+
i32.store $0 offset=4
2779+
local.get $1
2780+
call $~lib/object/Object#constructor
2781+
local.tee $this
2782+
i32.store $0
2783+
local.get $this
2784+
local.set $1
2785+
global.get $~lib/memory/__stack_pointer
2786+
local.get $1
2787+
i32.store $0 offset=4
2788+
local.get $1
2789+
i32.const 10
2790+
call $constructor/CtorFieldInitWithoutConstructor#set:a
2791+
local.get $this
2792+
local.set $1
2793+
global.get $~lib/memory/__stack_pointer
2794+
local.get $1
2795+
i32.store $0 offset=4
2796+
local.get $1
2797+
local.get $this
2798+
local.set $1
2799+
global.get $~lib/memory/__stack_pointer
2800+
local.get $1
2801+
i32.store $0 offset=8
2802+
local.get $1
2803+
call $constructor/CtorFieldInitWithoutConstructor#get:a
2804+
call $constructor/CtorFieldInitWithoutConstructor#set:b
2805+
local.get $this
2806+
local.set $1
2807+
global.get $~lib/memory/__stack_pointer
2808+
i32.const 12
2809+
i32.add
2810+
global.set $~lib/memory/__stack_pointer
2811+
local.get $1
2812+
)
27292813
(func $constructor/CtorFieldInitOrder#constructor (param $this i32) (param $a i32) (param $b i32) (result i32)
27302814
(local $3 i32)
27312815
global.get $~lib/memory/__stack_pointer
@@ -2744,7 +2828,7 @@
27442828
if
27452829
global.get $~lib/memory/__stack_pointer
27462830
i32.const 12
2747-
i32.const 14
2831+
i32.const 15
27482832
call $~lib/rt/itcms/__new
27492833
local.tee $this
27502834
i32.store $0
@@ -2794,7 +2878,7 @@
27942878
if
27952879
i32.const 0
27962880
i32.const 432
2797-
i32.const 93
2881+
i32.const 101
27982882
i32.const 5
27992883
call $~lib/builtins/abort
28002884
unreachable
@@ -2812,7 +2896,7 @@
28122896
if
28132897
i32.const 0
28142898
i32.const 432
2815-
i32.const 94
2899+
i32.const 102
28162900
i32.const 5
28172901
call $~lib/builtins/abort
28182902
unreachable
@@ -2824,7 +2908,7 @@
28242908
if
28252909
i32.const 0
28262910
i32.const 432
2827-
i32.const 95
2911+
i32.const 103
28282912
i32.const 5
28292913
call $~lib/builtins/abort
28302914
unreachable
@@ -2842,7 +2926,7 @@
28422926
if
28432927
i32.const 0
28442928
i32.const 432
2845-
i32.const 96
2929+
i32.const 104
28462930
i32.const 5
28472931
call $~lib/builtins/abort
28482932
unreachable
@@ -2860,7 +2944,7 @@
28602944
if
28612945
i32.const 0
28622946
i32.const 432
2863-
i32.const 97
2947+
i32.const 105
28642948
i32.const 5
28652949
call $~lib/builtins/abort
28662950
unreachable
@@ -2931,6 +3015,44 @@
29313015
call $constructor/CtorConditionallyReturnsThis#constructor
29323016
global.set $constructor/ctorConditionallyReturnsThis
29333017
i32.const 0
3018+
call $constructor/CtorFieldInitWithoutConstructor#constructor
3019+
local.set $0
3020+
global.get $~lib/memory/__stack_pointer
3021+
local.get $0
3022+
i32.store $0
3023+
local.get $0
3024+
call $constructor/CtorFieldInitWithoutConstructor#get:a
3025+
i32.const 10
3026+
i32.eq
3027+
i32.eqz
3028+
if
3029+
i32.const 0
3030+
i32.const 432
3031+
i32.const 94
3032+
i32.const 1
3033+
call $~lib/builtins/abort
3034+
unreachable
3035+
end
3036+
i32.const 0
3037+
call $constructor/CtorFieldInitWithoutConstructor#constructor
3038+
local.set $0
3039+
global.get $~lib/memory/__stack_pointer
3040+
local.get $0
3041+
i32.store $0
3042+
local.get $0
3043+
call $constructor/CtorFieldInitWithoutConstructor#get:b
3044+
i32.const 10
3045+
i32.eq
3046+
i32.eqz
3047+
if
3048+
i32.const 0
3049+
i32.const 432
3050+
i32.const 95
3051+
i32.const 1
3052+
call $~lib/builtins/abort
3053+
unreachable
3054+
end
3055+
i32.const 0
29343056
i32.const 1
29353057
i32.const 2
29363058
call $constructor/CtorFieldInitOrder#constructor
@@ -2948,7 +3070,7 @@
29483070
if
29493071
i32.const 0
29503072
i32.const 432
2951-
i32.const 102
3073+
i32.const 110
29523074
i32.const 1
29533075
call $~lib/builtins/abort
29543076
unreachable
@@ -2966,7 +3088,7 @@
29663088
if
29673089
i32.const 0
29683090
i32.const 432
2969-
i32.const 103
3091+
i32.const 111
29703092
i32.const 1
29713093
call $~lib/builtins/abort
29723094
unreachable
@@ -2984,7 +3106,7 @@
29843106
if
29853107
i32.const 0
29863108
i32.const 432
2987-
i32.const 104
3109+
i32.const 112
29883110
i32.const 1
29893111
call $~lib/builtins/abort
29903112
unreachable

0 commit comments

Comments
 (0)