;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: wasm-merge %s primary %s.second secondary --skip-export-conflicts -all -S -o - | filecheck %s

;; Export a global with a subtype. It is imported using the supertype, and
;; after we merge, the type must be updated, including in the global.get from
;; the second module (that goes from super to sub).
(module
 ;; CHECK:      (type $super (sub (func)))
 (type $super (sub (func)))
 ;; CHECK:      (type $sub (sub final $super (func)))
 (type $sub (sub final $super (func)))

 ;; CHECK:      (type $2 (func))

 ;; CHECK:      (global $sub (ref $sub) (ref.func $sub))
 (global $sub (ref $sub) (ref.func $sub))

 ;; CHECK:      (export "sub" (global $sub))
 (export "sub" (global $sub))

 ;; CHECK:      (export "second-user" (func $second-user))

 ;; CHECK:      (func $sub (type $sub)
 ;; CHECK-NEXT:  (drop
 ;; CHECK-NEXT:   (global.get $sub)
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT: )
 (func $sub (type $sub)
  (drop
   (global.get $sub)
  )
 )
)

;; CHECK:      (func $second-user (type $2)
;; CHECK-NEXT:  (drop
;; CHECK-NEXT:   (block (result (ref $sub))
;; CHECK-NEXT:    (global.get $sub)
;; CHECK-NEXT:   )
;; CHECK-NEXT:  )
;; CHECK-NEXT: )
