mirror of
https://github.com/vlang/v.git
synced 2025-09-16 02:49:31 -04:00
This commit is contained in:
parent
075d17d66f
commit
7a56ebf23b
@ -735,7 +735,9 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
||||
}
|
||||
}
|
||||
}
|
||||
if !is_blank_ident && right_sym.kind != .placeholder && left_sym.kind != .interface_ {
|
||||
if !is_blank_ident && right_sym.kind != .placeholder && left_sym.kind != .interface_
|
||||
&& ((!right_type.has_flag(.generic) && !left_type.has_flag(.generic))
|
||||
|| right_sym.kind != left_sym.kind) {
|
||||
// Dual sides check (compatibility check)
|
||||
c.check_expected(right_type_unwrapped, left_type_unwrapped) or {
|
||||
// allow literal values to auto deref var (e.g.`for mut v in values { v = 1.0 }`)
|
||||
|
33
vlib/v/tests/assign_type_checking_with_generics_test.v
Normal file
33
vlib/v/tests/assign_type_checking_with_generics_test.v
Normal file
@ -0,0 +1,33 @@
|
||||
module main
|
||||
|
||||
pub type EventListener[T] = fn (T) !
|
||||
|
||||
pub type Check[T] = fn (T) bool
|
||||
|
||||
pub struct EventController[T] {
|
||||
mut:
|
||||
id int
|
||||
listeners map[int]EventListener[T]
|
||||
}
|
||||
|
||||
fn (mut ec EventController[T]) generate_id() int {
|
||||
return ec.id++
|
||||
}
|
||||
|
||||
pub fn (mut ec EventController[T]) override(listener EventListener[T]) EventController[T] {
|
||||
ec.listeners = {
|
||||
ec.generate_id(): listener
|
||||
}
|
||||
return ec
|
||||
}
|
||||
|
||||
fn use[T](_ EventController[T]) {}
|
||||
|
||||
struct Foo {}
|
||||
|
||||
struct Bar {}
|
||||
|
||||
fn test_main() {
|
||||
use(EventController[Foo]{})
|
||||
use(EventController[Bar]{})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user