Skip to content

Commit

Permalink
conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
MCausc78 committed Feb 11, 2024
1 parent 77a2219 commit 3035480
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 12 deletions.
65 changes: 65 additions & 0 deletions test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import time

pub type EventListener[T] = fn (T) !

struct Chan[T] {
c chan T
}

pub type Check[T] = fn (T) bool

struct EventWaiter[T] {
check ?Check[T]
c &Chan[T]
}

pub struct EventController[T] {
mut:
id int
wait_fors map[int]EventWaiter[T]
listeners map[int]EventListener[T]
}

fn (mut ec EventController[T]) generate_id() int {
return ec.id++
}


@[params]
pub struct EventWaitParams[T] {
pub:
check ?Check[T]
timeout ?time.Duration
}

pub fn (mut ec EventController[T]) wait(params EventWaitParams[T]) ?T {
mut c := Chan[T]{}
id := ec.generate_id()
ec.wait_fors[id] = EventWaiter[T]{
check: params.check
c: &mut c
}
defer {
ec.wait_fors.delete(id)
}
if timeout := params.timeout {
select {
e := <-c.c {
r := e
return r
}
timeout.nanoseconds() {
return none
}
}
}
return <-c.c
}

struct Foo {}
struct Bar {}

fn main() {
x := EventController[Foo]{}
y := EventController[Bar]{}
}
24 changes: 12 additions & 12 deletions vlib/v/tests/cast_interface_to_impl.v
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
interface Foo {
interface TheInterfaceItself {
f() int
}

struct Bar {}
struct SomeImplForTII1 {}

fn (_ Bar) f() int {
fn (_ SomeImplForTII1) f() int {
return 2
}

fn (_ Bar) secret1() int {
fn (_ SomeImplForTII1) secret1() int {
return 42
}

struct Baz {}
struct AnotherImplementation {}

fn (_ Baz) f() int {
fn (_ AnotherImplementation) f() int {
return 8
}

fn (_ Baz) secret2() int {
fn (_ AnotherImplementation) secret2() int {
return 84
}

fn h(foo Foo, i int) int {
fn h(foo TheInterfaceItself, i int) int {
j := foo.f()
match i {
0 {
return j + (foo as Bar).secret1()
return j + (foo as SomeImplForTII1).secret1()
}
1 {
return j + (foo as Baz).secret2()
return j + (foo as AnotherImplementation).secret2()
}
else {
return 1
Expand All @@ -38,6 +38,6 @@ fn h(foo Foo, i int) int {
}

fn test_casting_to_impl() {
assert h(Bar{}, 0) == 44
assert h(Baz{}, 1) == 92
assert h(SomeImplForTII1{}, 0) == 44
assert h(AnotherImplementation{}, 1) == 92
}

0 comments on commit 3035480

Please sign in to comment.