mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
This commit is contained in:
parent
d2fdbaf67e
commit
5d99138cb2
4 changed files with 34 additions and 5 deletions
|
@ -53,7 +53,7 @@ fn print_sol(dist []int) {
|
||||||
// to all other vertices using Bellman-Ford algorithm. The
|
// to all other vertices using Bellman-Ford algorithm. The
|
||||||
// function also detects negative weight cycle
|
// function also detects negative weight cycle
|
||||||
fn bellman_ford[T](graph [][]T, src int) {
|
fn bellman_ford[T](graph [][]T, src int) {
|
||||||
mut edges := build_map_edges_from_graph(graph)
|
mut edges := build_map_edges_from_graph[int](graph)
|
||||||
// this function was done to adapt a graph representation
|
// this function was done to adapt a graph representation
|
||||||
// by a adjacency matrix, to list of adjacency (using a MAP)
|
// by a adjacency matrix, to list of adjacency (using a MAP)
|
||||||
n_edges := edges.len // number of EDGES
|
n_edges := edges.len // number of EDGES
|
||||||
|
|
|
@ -1471,7 +1471,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
|
||||||
}
|
}
|
||||||
|
|
||||||
if func.generic_names.len > 0 {
|
if func.generic_names.len > 0 {
|
||||||
if has_generic {
|
if has_generic || node.concrete_types.any(it.has_flag(.generic)) {
|
||||||
if typ := c.table.resolve_generic_to_concrete(func.return_type, func.generic_names,
|
if typ := c.table.resolve_generic_to_concrete(func.return_type, func.generic_names,
|
||||||
node.concrete_types)
|
node.concrete_types)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
fn generic1[K, V](a map[K]V) string {
|
||||||
|
t := expect_map[K, V](a)
|
||||||
|
dump(t)
|
||||||
|
return '${t}'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generic2[K, V](a map[K]V) string {
|
||||||
|
t := expect_map(a)
|
||||||
|
dump(t)
|
||||||
|
return '${t}'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn expect_map[K, V](a map[K]V) map[K]V {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generics_with_generics_fn_return_map_type() {
|
||||||
|
a := {
|
||||||
|
'a': 1
|
||||||
|
}
|
||||||
|
b := {
|
||||||
|
1: 'a'
|
||||||
|
}
|
||||||
|
assert generic1(a) == "{'a': 1}"
|
||||||
|
assert generic1(b) == "{1: 'a'}"
|
||||||
|
assert generic2(a) == "{'a': 1}"
|
||||||
|
assert generic2(b) == "{1: 'a'}"
|
||||||
|
}
|
|
@ -9,16 +9,17 @@ fn pre_start[T, R](app T, config R) string {
|
||||||
return start(app, config.val)
|
return start(app, config.val)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start[T, R](app T, otherthing R) R {
|
fn start[T, R](app T, otherthing R) string {
|
||||||
println(otherthing)
|
println(otherthing)
|
||||||
return otherthing
|
return '${otherthing}'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_main() {
|
fn test_multiple_generic_resolve() {
|
||||||
app := App{}
|
app := App{}
|
||||||
testval := 'hello'
|
testval := 'hello'
|
||||||
config := Config[string]{
|
config := Config[string]{
|
||||||
val: testval
|
val: testval
|
||||||
}
|
}
|
||||||
|
|
||||||
assert pre_start(app, config) == 'hello'
|
assert pre_start(app, config) == 'hello'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue