Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrCai0907 committed Oct 8, 2023
1 parent 99f8cbf commit cbc29df
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/compiler/operator-overload-ambiguity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"asc_flags": [],
"stderr": [
"AS240: Operator '==' overloading ambiguity.",
"compare_nonnull_a == compare_nonnull_b;",
"AS240: Operator '==' overloading ambiguity.",
"compare_nonnull_b == compare_nonnull_a;",
"AS240: Operator '==' overloading ambiguity.",
"compare_nonnull_c == compare_nonnull_d;",
"AS240: Operator '==' overloading ambiguity.",
"compare_extend_1 == compare_extend_2;",
"EOF"
]
}
40 changes: 40 additions & 0 deletions tests/compiler/operator-overload-ambiguity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class A {
@operator("==") __eq(other: B): bool {
return true;
}
}
class B {
@operator("==") __eq(other: A): bool {
return true;
}
}
export function compare_nonnull(compare_nonnull_a: A, compare_nonnull_b: B): void {
compare_nonnull_a == compare_nonnull_b;
compare_nonnull_b == compare_nonnull_a;
}

class C {
@operator("==") static __eq(self: C | null, other: D | null): bool {
return true;
}
}
class D {
@operator("==") __eq(other: i32): bool {
return true;
}
}
export function compare_null(compare_nonnull_c: C | null, compare_nonnull_d: D | null): void {
compare_nonnull_c == compare_nonnull_d;
}


class PA extends A {}
class PB extends B {}
export function compare_extend(compare_extend_1: PA, compare_extend_2: PB): void {
compare_extend_1 == compare_extend_2;
}


export function end(): void {
ERROR("EOF");
}
81 changes: 81 additions & 0 deletions tests/compiler/operator-overload-non-ambiguity.debug.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
(module
(type $i32_i32_=>_none (func (param i32 i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
(type $none_=>_none (func))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(global $~lib/memory/__data_end i32 (i32.const 8))
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 32776))
(global $~lib/memory/__heap_base i32 (i32.const 32776))
(memory $0 0)
(table $0 1 1 funcref)
(elem $0 (i32.const 1))
(export "memory" (memory $0))
(export "compare_extends" (func $export:operator-overload-non-ambiguity/compare_extends))
(func $operator-overload-non-ambiguity/Base#__eq (param $this i32) (param $other i32) (result i32)
i32.const 1
return
)
(func $~stack_check
global.get $~lib/memory/__stack_pointer
global.get $~lib/memory/__data_end
i32.lt_s
if
i32.const 32800
i32.const 32848
i32.const 1
i32.const 1
call $~lib/builtins/abort
unreachable
end
)
(func $operator-overload-non-ambiguity/compare_extends (param $v1 i32) (param $v2 i32)
(local $2 i32)
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i64.const 0
i64.store $0
local.get $v1
local.set $2
global.get $~lib/memory/__stack_pointer
local.get $2
i32.store $0
local.get $2
local.get $v2
local.set $2
global.get $~lib/memory/__stack_pointer
local.get $2
i32.store $0 offset=4
local.get $2
call $operator-overload-non-ambiguity/Base#__eq
drop
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.add
global.set $~lib/memory/__stack_pointer
)
(func $export:operator-overload-non-ambiguity/compare_extends (param $0 i32) (param $1 i32)
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
local.get $0
i32.store $0
global.get $~lib/memory/__stack_pointer
local.get $1
i32.store $0 offset=4
local.get $0
local.get $1
call $operator-overload-non-ambiguity/compare_extends
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.add
global.set $~lib/memory/__stack_pointer
)
)
3 changes: 3 additions & 0 deletions tests/compiler/operator-overload-non-ambiguity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"asc_flags": []
}
62 changes: 62 additions & 0 deletions tests/compiler/operator-overload-non-ambiguity.release.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
(module
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
(type $i32_i32_=>_none (func (param i32 i32)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 33792))
(memory $0 0)
(export "memory" (memory $0))
(export "compare_extends" (func $export:operator-overload-non-ambiguity/compare_extends))
(func $export:operator-overload-non-ambiguity/compare_extends (param $0 i32) (param $1 i32)
(local $2 i32)
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.sub
global.set $~lib/memory/__stack_pointer
block $folding-inner0
global.get $~lib/memory/__stack_pointer
i32.const 1024
i32.lt_s
br_if $folding-inner0
global.get $~lib/memory/__stack_pointer
local.tee $2
local.get $0
i32.store $0
local.get $2
local.get $1
i32.store $0 offset=4
local.get $2
i32.const 8
i32.sub
global.set $~lib/memory/__stack_pointer
global.get $~lib/memory/__stack_pointer
i32.const 1024
i32.lt_s
br_if $folding-inner0
global.get $~lib/memory/__stack_pointer
local.tee $2
i64.const 0
i64.store $0
local.get $2
local.get $0
i32.store $0
local.get $2
local.get $1
i32.store $0 offset=4
local.get $2
i32.const 8
i32.add
global.set $~lib/memory/__stack_pointer
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.add
global.set $~lib/memory/__stack_pointer
return
end
i32.const 33824
i32.const 33872
i32.const 1
i32.const 1
call $~lib/builtins/abort
unreachable
)
)
12 changes: 12 additions & 0 deletions tests/compiler/operator-overload-non-ambiguity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Base {
@operator("==") __eq(other: Base): bool {
return true;
}
}

class P1 extends Base {}
class P2 extends Base {}

export function compare_extends(v1: P1, v2: P2): void {
v1 == v2;
}

0 comments on commit cbc29df

Please sign in to comment.