vlib: remove deprecated map{} usages as well as deprecated functions (#11035)

pull/11051/head
Daniel Däschle 2021-08-04 11:44:41 +02:00 committed by GitHub
parent b870f7a6f1
commit 800c0e5092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
142 changed files with 410 additions and 501 deletions

View File

@ -134,7 +134,7 @@ fn (vd VDoc) render_search_index(out Output) {
}
fn (mut vd VDoc) render_static_html(out Output) {
vd.assets = map{
vd.assets = {
'doc_css': vd.get_resource(css_js_assets[0], out)
'normalize_css': vd.get_resource(css_js_assets[1], out)
'doc_js': vd.get_resource(css_js_assets[2], out)

View File

@ -17,15 +17,15 @@ const (
excluded_dirs = ['cache', 'vlib']
supported_vcs_systems = ['git', 'hg']
supported_vcs_folders = ['.git', '.hg']
supported_vcs_update_cmds = map{
supported_vcs_update_cmds = {
'git': 'git pull'
'hg': 'hg pull --update'
}
supported_vcs_install_cmds = map{
supported_vcs_install_cmds = {
'git': 'git clone --depth=1'
'hg': 'hg clone'
}
supported_vcs_outdated_steps = map{
supported_vcs_outdated_steps = {
'git': ['git fetch', 'git rev-parse @', 'git rev-parse @{u}']
'hg': ['hg incoming']
}
@ -467,7 +467,7 @@ fn resolve_dependencies(name string, module_path string, module_names []string)
fn parse_vmod(data string) Vmod {
keys := ['name', 'version', 'deps']
mut m := map{
mut m := {
'name': ''
'version': ''
'deps': ''

View File

@ -12,7 +12,7 @@ const (
support_color = term.can_show_color_on_stderr() && term.can_show_color_on_stdout()
ecode_timeout = 101
ecode_memout = 102
ecode_details = map{
ecode_details = {
-1: 'worker executable not found'
101: 'too slow'
102: 'too memory hungry'

View File

@ -1042,7 +1042,7 @@ Maps can have keys of type string, rune, integer, float or voidptr.
The whole map can be initialized using this short syntax:
```v
numbers := map{
numbers := {
'one': 1
'two': 2
}
@ -1052,14 +1052,14 @@ println(numbers)
If a key is not found, a zero value is returned by default:
```v
sm := map{
sm := {
'abc': 'xyz'
}
val := sm['bad_key']
println(val) // ''
```
```v
intm := map{
intm := {
1: 1234
2: 5678
}
@ -1306,7 +1306,7 @@ To do the opposite, use `!in`.
nums := [1, 2, 3]
println(1 in nums) // true
println(4 !in nums) // true
m := map{
m := {
'one': 1
'two': 2
}
@ -1421,7 +1421,7 @@ The code above prints:
##### Map `for`
```v
m := map{
m := {
'one': 1
'two': 2
}
@ -1434,7 +1434,7 @@ for key, value in m {
Either key or value can be ignored by using a single underscore as the identifier.
```v
m := map{
m := {
'one': 1
'two': 2
}
@ -1783,7 +1783,7 @@ mut p := Point{
y: 20
}
// you can omit the struct name when it's already known
p = {
p = Point{
x: 30
y: 4
}
@ -1935,7 +1935,7 @@ clr1 := Rgba32{
}
clr2 := Rgba32{
Rgba32_Component: {
Rgba32_Component: Rgba32_Component{
a: 128
}
}
@ -2029,7 +2029,7 @@ struct User {
}
fn register(u User) User {
return {
return User{
...u
is_registered: true
}
@ -2095,7 +2095,7 @@ fn main() {
// You can even have an array/map of functions:
fns := [sqr, cube]
println(fns[0](10)) // "100"
fns_map := map{
fns_map := {
'sqr': sqr
'cube': cube
}

View File

@ -26,7 +26,7 @@ fn breadth_first_search_path(graph map[string][]string, vertex string, target st
}
fn main() {
graph := map{
graph := {
'A': ['B', 'C']
'B': ['A', 'D', 'E']
'C': ['A', 'F']

View File

@ -503,7 +503,7 @@ fn main(){
gg: 0
}
app.gg = gg.new_context({
app.gg = gg.new_context(
width: win_width
height: win_height
create_window: true
@ -514,7 +514,7 @@ fn main(){
init_fn: my_init
cleanup_fn: cleanup
event_fn: my_event_manager
})
)
app.ticks = time.ticks()
app.gg.run()

View File

@ -338,22 +338,6 @@ pub fn (instance BitField) clone() BitField {
return output
}
// cmp compares two bit arrays bit by bit and returns 'true' if they are
// identical by length and contents and 'false' otherwise.
[deprecated: 'use a == b instead']
[deprecated_after: '2021-06-29']
pub fn (instance BitField) cmp(input BitField) bool {
if instance.size != input.size {
return false
}
for i in 0 .. zbitnslots(instance.size) {
if instance.field[i] != input.field[i] {
return false
}
}
return true
}
pub fn (a BitField) == (b BitField) bool {
if a.size != b.size {
return false

View File

@ -745,13 +745,13 @@ fn test_eq() {
age: 22
name: 'bob'
}]
assert [map{
assert [{
'bob': 22
}, map{
}, {
'tom': 33
}] == [map{
}] == [{
'bob': 22
}, map{
}, {
'tom': 33
}]
assert [[1, 2, 3], [4]] == [[1, 2, 3], [4]]
@ -1315,20 +1315,20 @@ fn test_struct_array_of_multi_type_in() {
ivan := Person{
name: 'ivan'
nums: [1, 2, 3]
kv: map{
kv: {
'aaa': '111'
}
}
people := [Person{
name: 'ivan'
nums: [1, 2, 3]
kv: map{
kv: {
'aaa': '111'
}
}, Person{
name: 'bob'
nums: [2]
kv: map{
kv: {
'bbb': '222'
}
}]
@ -1340,20 +1340,20 @@ fn test_struct_array_of_multi_type_index() {
ivan := Person{
name: 'ivan'
nums: [1, 2, 3]
kv: map{
kv: {
'aaa': '111'
}
}
people := [Person{
name: 'ivan'
nums: [1, 2, 3]
kv: map{
kv: {
'aaa': '111'
}
}, Person{
name: 'bob'
nums: [2]
kv: map{
kv: {
'bbb': '222'
}
}]

View File

@ -12,7 +12,7 @@ fn test_map_of_f32() {
}
fn test_map_of_f64() {
mut m64 := map{
mut m64 := {
3.14: 'pi'
}
m64[1.0] = 'one'

View File

@ -130,7 +130,7 @@ fn test_map() {
fn test_map_init() {
one := 'one'
three := 'three'
m := map{
m := {
one: 1
'two': 2
three: 1 + 2
@ -346,25 +346,25 @@ fn test_map_assign() {
mut a := map[string]f64{}
mut b := map[string]int{}
mut c := map[string]u16{}
a = map{
a = {
'x': 12.4
'y': 3
}
b = map{
b = {
'u': -13
'v': 12
}
c = map{
c = {
's': u16(5)
't': 3
}
_ := Mstruct1{map{
_ := Mstruct1{{
'p': 12
}}
_ := Mstruct2{map{
_ := Mstruct2{{
'q': 1.7
}}
_ := Mstruct3{map{
_ := Mstruct3{{
'r': u16(6)
's': 5
}}
@ -398,7 +398,7 @@ fn test_assign_directly() {
}
fn test_map_in_directly() {
for k, v in map{
for k, v in {
'aa': 1
} {
assert k == 'aa'
@ -407,7 +407,7 @@ fn test_map_in_directly() {
}
fn test_plus_assign_string() {
mut m := map{
mut m := {
'one': ''
}
m['one'] += '1'
@ -416,7 +416,7 @@ fn test_plus_assign_string() {
}
fn test_map_keys_to_array() {
m := map{
m := {
'a': 'b'
'c': 'd'
}
@ -436,7 +436,7 @@ fn map_in_mut(mut m map[string]int) {
}
fn test_map_in_mut() {
mut m := map{
mut m := {
'one': 1
}
map_in_mut(mut m)
@ -444,7 +444,7 @@ fn test_map_in_mut() {
}
fn test_map_in() {
m := map{
m := {
'Foo': 'bar'
}
if 'foo'.capitalize() in m {
@ -476,7 +476,7 @@ fn mut_map_with_relation_op_in_fn(mut m map[string]int) {
}
fn test_mut_map_with_relation_op_in_fn() {
mut m := map{
mut m := {
'one': 1
'two': 2
}
@ -490,7 +490,7 @@ fn test_mut_map_with_relation_op_in_fn() {
}
fn test_map_str_after_delete() {
mut m := map{
mut m := {
'first': 1
'second': 2
'third': 3
@ -504,7 +504,7 @@ fn test_map_str_after_delete() {
}
fn test_modify_map_value() {
mut m1 := map{
mut m1 := {
'foo': 3
'bar': -7
}
@ -515,7 +515,7 @@ fn test_modify_map_value() {
}
fn test_map_clone() {
mut nums := map{
mut nums := {
'foo': 1
'bar': 2
}
@ -542,7 +542,7 @@ fn test_map_default_zero() {
}
fn test_map_or() {
m := map{
m := {
'first': 1
'second': 2
'third': 3
@ -561,7 +561,7 @@ fn test_int_keys() {
m[5] += 24
m[5]++
assert m[5] == 25
mut m2 := map{
mut m2 := {
3: 9
4: 16
5: 25
@ -577,7 +577,7 @@ fn test_int_keys() {
assert m2[5] == 0
assert m2.keys() == []
m2 = map{
m2 = {
3: 9
4: 16
5: 25
@ -598,7 +598,7 @@ fn test_int_keys() {
}
assert all == [3, 9, 4, 16, 5, 25]
mut m3 := map{
mut m3 := {
1: 'one'
2: 'two'
}
@ -639,7 +639,7 @@ fn test_voidptr_keys() {
}
fn test_rune_keys() {
mut m := map{
mut m := {
`!`: 2
`%`: 3
}
@ -659,62 +659,62 @@ fn test_rune_keys() {
}
fn test_eq() {
a := map{
a := {
'a': 1
'b': 2
}
assert a == map{
assert a == {
'a': 1
'b': 2
}
b := map{
b := {
'a': [[1]]
'b': [[2]]
}
assert b == map{
assert b == {
'a': [[1]]
'b': [[2]]
}
c := map{
'a': map{
c := {
'a': {
'11': 1
}
'b': map{
'b': {
'22': 2
}
}
assert c == map{
'a': map{
assert c == {
'a': {
'11': 1
}
'b': map{
'b': {
'22': 2
}
}
d := map{
d := {
'a': MValue{
name: 'aa'
misc: map{
misc: {
'11': '1'
}
}
'b': MValue{
name: 'bb'
misc: map{
misc: {
'22': '2'
}
}
}
assert d == map{
assert d == {
'a': MValue{
name: 'aa'
misc: map{
misc: {
'11': '1'
}
}
'b': MValue{
name: 'bb'
misc: map{
misc: {
'22': '2'
}
}
@ -722,31 +722,31 @@ fn test_eq() {
}
fn test_non_string_key_map_str() {
assert map{
assert {
23: 4
}.str() == '{23: 4}'
assert map{
assert {
`a`: 12
`b`: 13
}.str() == '{`a`: 12, `b`: 13}'
assert map{
assert {
23: 'foo'
25: 'bar'
}.str() == "{23: 'foo', 25: 'bar'}"
}
fn test_map_assign_empty_map_init() {
mut a := map{
mut a := {
'one': 1
}
a = map{}
a = {}
println(a)
assert a == map[string]int{}
assert '$a' == '{}'
}
fn test_in_map_literal() {
assert 1 in map{
assert 1 in {
1: 'one'
}
}

View File

@ -205,7 +205,7 @@ pub fn (c Color) abgr8() int {
}
const (
string_colors = map{
string_colors = {
'blue': blue
'red': red
'green': green

View File

@ -7,7 +7,7 @@ fn C.wyhash(&byte, u64, u64, &u64) u64
fn C.wyhash64(u64, u64) u64
fn init() {
_ := map{
_ := {
1: 1
}
}

View File

@ -9,16 +9,6 @@ pub interface Reader {
read(mut buf []byte) ?int
}
// make_reader is a temp that converts a type to a reader
// (e.g. for use in struct initialisation)
// (this shouldnt need to be a thing but until coercion gets made better
// it is required)
[deprecated: 'use just `x` instead of `io.make_reader(x)`. Interfaces are now checked against all types.']
[deprecated_after: '2021-05-27']
pub fn make_reader(r Reader) Reader {
return r
}
const (
read_all_len = 10 * 1024
read_all_grow_len = 1024

View File

@ -151,7 +151,7 @@ fn test_struct_in_struct() ? {
fn test_encode_map() {
expected := '{"one":1,"two":2,"three":3,"four":4}'
numbers := map{
numbers := {
'one': 1
'two': 2
'three': 3
@ -163,7 +163,7 @@ fn test_encode_map() {
}
fn test_parse_map() ? {
expected := map{
expected := {
'one': 1
'two': 2
'three': 3
@ -193,7 +193,7 @@ fn test_nested_type() ? {
cities: [City{'Donlon'}, City{'Termanches'}]
},
]
users: map{
users: {
'Foo': User{
age: 10
nums: [1, 2, 3]
@ -211,14 +211,14 @@ fn test_nested_type() ? {
pets: 'little boo'
}
}
extra: map{
'2': map{
extra: {
'2': {
'n1': 2
'n2': 4
'n3': 8
'n4': 16
}
'3': map{
'3': {
'n1': 3
'n2': 9
'n3': 27

View File

@ -14,7 +14,7 @@ mut:
opened_code_type string
line_count int
lexeme_builder strings.Builder = strings.new_builder(100)
code_tags map[string]bool = map{
code_tags map[string]bool = {
'script': true
'style': true
}

View File

@ -257,7 +257,7 @@ const (
]
read_set_cookies_tests = [
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['Cookie-1=v1']
}
cookies: [&http.Cookie{
@ -292,7 +292,7 @@ const (
// }]
// },
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['ASP.NET_SessionId=foo; path=/; HttpOnly']
}
cookies: [
@ -306,7 +306,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['samesitedefault=foo; SameSite']
}
cookies: [
@ -319,7 +319,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['samesitelax=foo; SameSite=Lax']
}
cookies: [
@ -332,7 +332,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['samesitestrict=foo; SameSite=Strict']
}
cookies: [
@ -345,7 +345,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['samesitenone=foo; SameSite=None']
}
cookies: [
@ -360,7 +360,7 @@ const (
// Make sure we can properly read back the Set-Cookie headers we create
// for values containing spaces or commas:
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['special-1=a z']
}
cookies: [
@ -372,7 +372,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['special-2=" z"']
}
cookies: [
@ -384,7 +384,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['special-3="a "']
}
cookies: [
@ -396,7 +396,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['special-4=" "']
}
cookies: [
@ -408,7 +408,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['special-5=a,z']
}
cookies: [
@ -420,7 +420,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['special-6=",z"']
}
cookies: [
@ -432,7 +432,7 @@ const (
]
},
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['special-7=","']
}
cookies: [

View File

@ -216,7 +216,7 @@ pub fn (h CommonHeader) str() string {
}
}
const common_header_map = map{
const common_header_map = {
'accept': CommonHeader.accept
'accept-ch': .accept_ch
'accept-charset': .accept_charset

View File

@ -276,7 +276,7 @@ fn test_str() ? {
}
fn test_header_from_map() ? {
h := new_header_from_map(map{
h := new_header_from_map({
CommonHeader.accept: 'nothing'
CommonHeader.expires: 'yesterday'
})
@ -287,7 +287,7 @@ fn test_header_from_map() ? {
}
fn test_custom_header_from_map() ? {
h := new_custom_header_from_map(map{
h := new_custom_header_from_map({
'Server': 'VWeb'
'foo': 'bar'
}) ?
@ -298,11 +298,11 @@ fn test_custom_header_from_map() ? {
}
fn test_header_join() ? {
h1 := new_header_from_map(map{
h1 := new_header_from_map({
CommonHeader.accept: 'nothing'
CommonHeader.expires: 'yesterday'
})
h2 := new_custom_header_from_map(map{
h2 := new_custom_header_from_map({
'Server': 'VWeb'
'foo': 'bar'
}) ?
@ -329,27 +329,27 @@ fn parse_headers_test(s string, expected map[string]string) ? {
}
fn test_parse_headers() ? {
parse_headers_test('foo: bar', map{
parse_headers_test('foo: bar', {
'foo': 'bar'
}) ?
parse_headers_test('foo: \t bar', map{
parse_headers_test('foo: \t bar', {
'foo': 'bar'
}) ?
parse_headers_test('foo: bar\r\n\tbaz', map{
parse_headers_test('foo: bar\r\n\tbaz', {
'foo': 'bar baz'
}) ?
parse_headers_test('foo: bar \r\n\tbaz\r\n buzz', map{
parse_headers_test('foo: bar \r\n\tbaz\r\n buzz', {
'foo': 'bar baz buzz'
}) ?
parse_headers_test('foo: bar\r\nbar:baz', map{
parse_headers_test('foo: bar\r\nbar:baz', {
'foo': 'bar'
'bar': 'baz'
}) ?
parse_headers_test('foo: bar\r\nbar:baz\r\n', map{
parse_headers_test('foo: bar\r\nbar:baz\r\n', {
'foo': 'bar'
'bar': 'baz'
}) ?
parse_headers_test('foo: bar\r\nbar:baz\r\n\r\n', map{
parse_headers_test('foo: bar\r\nbar:baz\r\n\r\n', {
'foo': 'bar'
'bar': 'baz'
}) ?

View File

@ -59,7 +59,7 @@ fn test_http_fetch_with_params() {
return
}
responses := http_fetch_mock([],
params: map{
params: {
'a': 'b'
'c': 'd'
}

View File

@ -71,27 +71,27 @@ fn test_parse_request_line() {
}
fn test_parse_form() {
assert parse_form('foo=bar&bar=baz') == map{
assert parse_form('foo=bar&bar=baz') == {
'foo': 'bar'
'bar': 'baz'
}
assert parse_form('foo=bar=&bar=baz') == map{
assert parse_form('foo=bar=&bar=baz') == {
'foo': 'bar='
'bar': 'baz'
}
assert parse_form('foo=bar%3D&bar=baz') == map{
assert parse_form('foo=bar%3D&bar=baz') == {
'foo': 'bar='
'bar': 'baz'
}
assert parse_form('foo=b%26ar&bar=baz') == map{
assert parse_form('foo=b%26ar&bar=baz') == {
'foo': 'b&ar'
'bar': 'baz'
}
assert parse_form('a=b& c=d') == map{
assert parse_form('a=b& c=d') == {
'a': 'b'
' c': 'd'
}
assert parse_form('a=b&c= d ') == map{
assert parse_form('a=b&c= d ') == {
'a': 'b'
'c': ' d '
}
@ -115,7 +115,7 @@ ${contents[1]}
--------------------------$boundary--
"
form, files := parse_multipart_form(data, boundary)
assert files == map{
assert files == {
names[0]: [FileData{
filename: file
content_type: ct
@ -123,7 +123,7 @@ ${contents[1]}
}]
}
assert form == map{
assert form == {
names[1]: contents[1]
}
}

View File

@ -8,7 +8,7 @@ pub const (
float = [13, 14]
string = 18
time = -2
type_idx = map{
type_idx = {
'i8': 5
'i16': 6
'int': 7

View File

@ -1213,7 +1213,7 @@ pub:
pub const (
// reference: https://en.wikipedia.org/wiki/X86#/media/File:Table_of_x86_Registers_svg.svg
// map register size -> register name
x86_no_number_register_list = map{
x86_no_number_register_list = {
8: ['al', 'ah', 'bl', 'bh', 'cl', 'ch', 'dl', 'dh', 'bpl', 'sil', 'dil', 'spl']
16: ['ax', 'bx', 'cx', 'dx', 'bp', 'si', 'di', 'sp', /* segment registers */ 'cs', 'ss',
'ds', 'es', 'fs', 'gs', 'flags', 'ip', /* task registers */ 'gdtr', 'idtr', 'tr', 'ldtr',
@ -1240,32 +1240,32 @@ pub const (
// st#: floating point numbers
// cr#: control/status registers
// dr#: debug registers
x86_with_number_register_list = map{
8: map{
x86_with_number_register_list = {
8: {
'r#b': 16
}
16: map{
16: {
'r#w': 16
}
32: map{
32: {
'r#d': 16
}
64: map{
64: {
'r#': 16
'mm#': 16
'cr#': 16
'dr#': 16
}
80: map{
80: {
'st#': 16
}
128: map{
128: {
'xmm#': 32
}
256: map{
256: {
'ymm#': 32
}
512: map{
512: {
'zmm#': 32
}
}
@ -1277,14 +1277,14 @@ pub const (
'sp' /* aka r13 */, 'lr' /* aka r14 */, /* this is instruction pointer ('program counter'): */
'pc' /* aka r15 */,
] // 'cpsr' and 'apsr' are special flags registers, but cannot be referred to directly
arm_with_number_register_list = map{
arm_with_number_register_list = {
'r#': 16
}
)
pub const (
riscv_no_number_register_list = ['zero', 'ra', 'sp', 'gp', 'tp']
riscv_with_number_register_list = map{
riscv_with_number_register_list = {
'x#': 32
't#': 3
's#': 12

View File

@ -1338,13 +1338,6 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
}
node.left_type = map_info.key_type
}
.string {
c.warn('use `str.contains(substr)` instead of `substr in str`', left_right_pos)
c.check_expected(left_type, right_type) or {
c.error('left operand to `$node.op` does not match: $err.msg',
left_right_pos)
}
}
else {
c.error('`$node.op.str()` can only be used with an array/map/string',
node.pos)

View File

@ -1,14 +1,14 @@
type Map = map[string]string
pub fn new_map() Map {
return Map(map{
return Map({
'23': 'str'
})
}
fn (a Map) + (b Map) Map {
str := b['23']
return Map(map{
return Map({
'34': str + '12'
})
}

View File

@ -11,10 +11,10 @@ vlib/v/checker/tests/array_or_map_assign_err.vv:5:5: error: use `array2 = array1
5 | a3 = a1
| ^
6 |
7 | m1 := map{'one': 1}
7 | m1 := {'one': 1}
vlib/v/checker/tests/array_or_map_assign_err.vv:8:8: error: cannot copy map: call `move` or `clone` method (or use a reference)
6 |
7 | m1 := map{'one': 1}
7 | m1 := {'one': 1}
8 | m2 := m1
| ~~
9 | mut m3 := map[string]int{}

View File

@ -4,7 +4,7 @@ fn main() {
mut a3 := []int{}
a3 = a1
m1 := map{'one': 1}
m1 := {'one': 1}
m2 := m1
mut m3 := map[string]int{}
m3 = m1
@ -12,7 +12,7 @@ fn main() {
_ = a2
_ = m2
mut m := map{'foo':1}
mut m := {'foo':1}
foo(mut m)
_ = a3

View File

@ -1,6 +1,6 @@
vlib/v/checker/tests/assign_expr_undefined_err_k.vv:2:22: error: undefined variable: `a`
vlib/v/checker/tests/assign_expr_undefined_err_k.vv:2:19: error: undefined variable: `a`
1 | fn main() {
2 | mut a := map{'one': a}
| ^
2 | mut a := {'one': a}
| ^
3 | println(a)
4 | }
4 | }

View File

@ -1,4 +1,4 @@
fn main() {
mut a := map{'one': a}
mut a := {'one': a}
println(a)
}

View File

@ -1,8 +1,8 @@
vlib/v/checker/tests/for_in_map_one_variable_err.vv:3:6: error: declare a key and a value variable when ranging a map: `for key, val in map {`
use `_` if you do not need the variable
1 | fn main() {
2 | kvs := map{'foo':'bar'}
2 | kvs := {'foo':'bar'}
3 | for k in kvs {
| ^
4 | println('$k')
5 | }
5 | }

View File

@ -1,5 +1,5 @@
fn main() {
kvs := map{'foo':'bar'}
kvs := {'foo':'bar'}
for k in kvs {
println('$k')
}

View File

@ -14,7 +14,7 @@ vlib/v/checker/tests/for_in_mut_val_type.vv:7:15: error: `a2` is immutable, it c
9 | }
vlib/v/checker/tests/for_in_mut_val_type.vv:11:18: error: `m` is immutable, it cannot be changed
9 | }
10 | m := map{'aa': 1, 'bb': 2}
10 | m := {'aa': 1, 'bb': 2}
11 | for _, mut j in m {
| ^
12 | j *= 2
@ -33,10 +33,10 @@ vlib/v/checker/tests/for_in_mut_val_type.vv:17:15: error: array literal is immut
| ~~~~~~~~~~
18 | j *= 2
19 | }
vlib/v/checker/tests/for_in_mut_val_type.vv:20:21: error: map literal is immutable, it cannot be changed
vlib/v/checker/tests/for_in_mut_val_type.vv:20:18: error: map literal is immutable, it cannot be changed
18 | j *= 2
19 | }
20 | for _, mut j in map{'aa': 1, 'bb': 2} {
| ~~~~~~~~~~~~~~~~~~
20 | for _, mut j in {'aa': 1, 'bb': 2} {
| ~~~~~~~~~~~~~~~~~~
21 | j *= 2
22 | }

View File

@ -7,7 +7,7 @@ fn main() {
for mut j in a2 {
j *= 2
}
m := map{'aa': 1, 'bb': 2}
m := {'aa': 1, 'bb': 2}
for _, mut j in m {
j *= 2
}
@ -17,7 +17,7 @@ fn main() {
for mut j in [1, 2, 3]! {
j *= 2
}
for _, mut j in map{'aa': 1, 'bb': 2} {
for _, mut j in {'aa': 1, 'bb': 2} {
j *= 2
}
}

View File

@ -10,10 +10,10 @@ vlib/v/checker/tests/import_symbol_private_err.vv:4:13: error: module `io` type
3 | import time { now, since }
4 | import io { ReaderWriterImpl }
| ~~~~~~~~~~~~~~~~
5 |
5 |
6 | fn main() {
vlib/v/checker/tests/import_symbol_private_err.vv:7:18: error: constant `v.scanner.single_quote` is private
5 |
5 |
6 | fn main() {
7 | println(scanner.single_quote)
| ~~~~~~~~~~~~
@ -25,24 +25,24 @@ vlib/v/checker/tests/import_symbol_private_err.vv:8:17: error: enum `v.parser.St
8 | println(parser.State.html)
| ~~~~~~~~~~
9 | since(now())
10 | _ = map{'h': 2}.exists('h')
10 | _ = {'h': 2}.exists('h')
vlib/v/checker/tests/import_symbol_private_err.vv:9:2: error: function `time.since` is private
7 | println(scanner.single_quote)
8 | println(parser.State.html)
9 | since(now())
| ~~~~~~~~~~~~
10 | _ = map{'h': 2}.exists('h')
10 | _ = {'h': 2}.exists('h')
11 | _ = ReaderWriterImpl{}
vlib/v/checker/tests/import_symbol_private_err.vv:10:18: error: method `map[string]int.exists` is private
vlib/v/checker/tests/import_symbol_private_err.vv:10:15: error: method `map[string]int.exists` is private
8 | println(parser.State.html)
9 | since(now())
10 | _ = map{'h': 2}.exists('h')
| ~~~~~~~~~~~
10 | _ = {'h': 2}.exists('h')
| ~~~~~~~~~~~
11 | _ = ReaderWriterImpl{}
12 | }
vlib/v/checker/tests/import_symbol_private_err.vv:11:6: error: type `io.ReaderWriterImpl` is private
9 | since(now())
10 | _ = map{'h': 2}.exists('h')
10 | _ = {'h': 2}.exists('h')
11 | _ = ReaderWriterImpl{}
| ~~~~~~~~~~~~~~~~~~
12 | }
12 | }

View File

@ -7,6 +7,6 @@ fn main() {
println(scanner.single_quote)
println(parser.State.html)
since(now())
_ = map{'h': 2}.exists('h')
_ = {'h': 2}.exists('h')
_ = ReaderWriterImpl{}
}

View File

@ -12,18 +12,18 @@ vlib/v/checker/tests/in_mismatch_type.vv:13:5: error: left operand to `in` does
| ~~~~~~
14 | println('yeah')
15 | }
vlib/v/checker/tests/in_mismatch_type.vv:16:5: error: use `str.contains(substr)` instead of `substr in str`
vlib/v/checker/tests/in_mismatch_type.vv:16:7: error: `in` can only be used with an array/map/string
14 | println('yeah')
15 | }
16 | if 3 in s {
| ~~~~~~
| ~~
17 | println('dope')
18 | }
vlib/v/checker/tests/in_mismatch_type.vv:19:5: error: use `str.contains(substr)` instead of `substr in str`
vlib/v/checker/tests/in_mismatch_type.vv:19:9: error: `in` can only be used with an array/map/string
17 | println('dope')
18 | }
19 | if `a` in s {
| ~~~~~~~~
| ~~
20 | println("oh no :'(")
21 | }
vlib/v/checker/tests/in_mismatch_type.vv:22:7: error: `in` can only be used with an array/map/string
@ -74,4 +74,4 @@ vlib/v/checker/tests/in_mismatch_type.vv:41:5: error: left operand to `!in` does
41 | if 5 !in m {
| ~~~~~~~
42 | println('yay')
43 | }
43 | }

View File

@ -3,7 +3,7 @@ type Int = int
fn main() {
a_i := [1, 2, 3]
a_s := ['1', '2', '3']
m := map{
m := {
'test': 1
}
s := 'abcd'

View File

@ -4,13 +4,13 @@ vlib/v/checker/tests/map_delete.vv:5:11: error: cannot use `int literal` as `str
5 | m.delete(1)
| ^
6 | m.delete(1, 2)
7 | m2 := map{
7 | m2 := {
vlib/v/checker/tests/map_delete.vv:6:4: error: expected 1 argument, but got 2
4 | }
5 | m.delete(1)
6 | m.delete(1, 2)
| ~~~~~~~~~~~~
7 | m2 := map{
7 | m2 := {
8 | '1': 1
vlib/v/checker/tests/map_delete.vv:10:2: error: `m2` is immutable, declare it with `mut` to make it mutable
8 | '1': 1

View File

@ -1,10 +1,10 @@
fn main() {
mut m := map{
mut m := {
'1': 1
}
m.delete(1)
m.delete(1, 2)
m2 := map{
m2 := {
'1': 1
}
m2.delete('1')

View File

@ -1,6 +1,6 @@
vlib/v/checker/tests/map_init_invalid_syntax.vv:2:10: error: invalid empty map initilization syntax, use e.g. map[string]int{} instead
vlib/v/checker/tests/map_init_invalid_syntax.vv:2:7: error: invalid empty map initilization syntax, use e.g. map[string]int{} instead
1 | fn main() {
2 | a := map{}
| ~~
2 | a := {}
| ~~
3 | println(a)
4 | }
4 | }

View File

@ -1,4 +1,4 @@
fn main() {
a := map{}
a := {}
println(a)
}

View File

@ -5,9 +5,9 @@ vlib/v/checker/tests/map_init_key_duplicate_err.vv:5:3: error: duplicate key "fo
| ~~~~~
6 | }
7 | println(a)
vlib/v/checker/tests/map_init_key_duplicate_err.vv:9:18: error: duplicate key "2" in map literal
vlib/v/checker/tests/map_init_key_duplicate_err.vv:9:15: error: duplicate key "2" in map literal
7 | println(a)
8 |
9 | _ = map{2:0 3:0 2:0}
| ^
9 | _ = {2:0 3:0 2:0}
| ^
10 | }

View File

@ -1,10 +1,10 @@
fn main() {
a := map{
a := {
'foo': 'bar'
'abc': 'abc'
'foo': 'bar'
}
println(a)
_ = map{2:0 3:0 2:0}
_ = {2:0 3:0 2:0}
}

View File

@ -1,21 +1,21 @@
vlib/v/checker/tests/map_init_wrong_type.vv:3:18: error: invalid map value: expected `f32`, not `float literal`
vlib/v/checker/tests/map_init_wrong_type.vv:3:15: error: invalid map value: expected `f32`, not `float literal`
1 | fn main() {
2 | mut a := map[string]f32{}
3 | a = map{ 'x': 12.3 }
| ~~~~
4 | _ = map{2:0 3:0 "hi":0}
5 | _ = map{2:0 3:`@` 4:0}
vlib/v/checker/tests/map_init_wrong_type.vv:4:20: error: invalid map key: expected `int`, not `string`
3 | a = { 'x': 12.3 }
| ~~~~
4 | _ = {2:0 3:0 "hi":0}
5 | _ = {2:0 3:`@` 4:0}
vlib/v/checker/tests/map_init_wrong_type.vv:4:17: error: invalid map key: expected `int`, not `string`
2 | mut a := map[string]f32{}
3 | a = map{ 'x': 12.3 }
4 | _ = map{2:0 3:0 "hi":0}
| ~~~~
5 | _ = map{2:0 3:`@` 4:0}
3 | a = { 'x': 12.3 }
4 | _ = {2:0 3:0 "hi":0}
| ~~~~
5 | _ = {2:0 3:`@` 4:0}
6 | _ = a
vlib/v/checker/tests/map_init_wrong_type.vv:5:18: error: invalid map value: expected `int`, not `rune`
3 | a = map{ 'x': 12.3 }
4 | _ = map{2:0 3:0 "hi":0}
5 | _ = map{2:0 3:`@` 4:0}
| ~~~
vlib/v/checker/tests/map_init_wrong_type.vv:5:15: error: invalid map value: expected `int`, not `rune`
3 | a = { 'x': 12.3 }
4 | _ = {2:0 3:0 "hi":0}
5 | _ = {2:0 3:`@` 4:0}
| ~~~
6 | _ = a
7 | }

View File

@ -1,7 +1,7 @@
fn main() {
mut a := map[string]f32{}
a = map{ 'x': 12.3 }
_ = map{2:0 3:0 "hi":0}
_ = map{2:0 3:`@` 4:0}
a = { 'x': 12.3 }
_ = {2:0 3:0 "hi":0}
_ = {2:0 3:`@` 4:0}
_ = a
}

View File

@ -1,7 +1,7 @@
vlib/v/checker/tests/mut_map_get_value_address_err.vv:3:12: error: cannot take the address of map values
1 | fn main() {
2 | mut m := map{'key' : 3}
2 | mut m := {'key' : 3}
3 | a := &m['key']
| ~~~~~~~
4 | println(a)
5 | }
5 | }

View File

@ -1,5 +1,5 @@
fn main() {
mut m := map{'key' : 3}
mut m := {'key' : 3}
a := &m['key']
println(a)
}

View File

@ -1,6 +1,6 @@
vlib/v/checker/tests/or_expr_types_mismatch.vv:3:19: error: wrong return type `none` in the `or {}` block, expected `string`
1 | fn get_map() ?string {
2 | m := map{1: 'a', 2: 'b'}
2 | m := {1: 'a', 2: 'b'}
3 | return m[1] or { none }
| ~~~~
4 | }

View File

@ -1,5 +1,5 @@
fn get_map() ?string {
m := map{1: 'a', 2: 'b'}
m := {1: 'a', 2: 'b'}
return m[1] or { none }
}

View File

@ -37,7 +37,7 @@ fn a_val(a []int) int {
fn test_shared_as_value() {
shared s := St{ a: 5 }
shared a := [3, 4, 6, 13, -23]
shared m := map{'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
shared r := Qr{ a: 7 }
lock s {
u := r.s_val(s)
@ -55,7 +55,7 @@ fn test_shared_as_value() {
fn test_shared_as_mut() {
shared s := St{ a: 5 }
shared a := [3, 4, 6, 13, -23]
shared m := map{'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
shared r := Qr{ a: 7 }
lock s {
r.s_mut(mut s)

View File

@ -1,13 +0,0 @@
vlib/v/checker/tests/struct_short_init_warning.vv:6:9: warning: short struct initalization is deprecated, use explicit struct name
4 |
5 | fn f(foo Foo) Foo {
6 | return {v: foo.v}
| ~~~~~~~~~~
7 | }
8 |
vlib/v/checker/tests/struct_short_init_warning.vv:10:4: warning: short struct initalization is deprecated, use explicit struct name
8 |
9 | fn main() {
10 | f({v: 10})
| ~~~~~~~
11 | }

View File

@ -1,11 +0,0 @@
struct Foo {
v int
}
fn f(foo Foo) Foo {
return {v: foo.v}
}
fn main() {
f({v: 10})
}

View File

@ -279,7 +279,7 @@ pub fn (mut d Doc) stmt(stmt ast.Stmt, filename string) ?DocNode {
kind: .variable
parent_name: node.name
pos: param.pos
attrs: map{
attrs: {
'mut': param.is_mut.str()
}
return_type: d.type_to_str(param.typ)

View File

@ -1970,14 +1970,11 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) {
info := sym.info as ast.Map
f.mark_types_import_as_used(info.key_type)
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
} else {
// m = map{}
f.write('map')
}
f.write('{}')
return
}
f.writeln('map{')
f.writeln('{')
f.indent++
f.comments(node.pre_cmnts)
mut max_field_len := 0

View File

@ -3,7 +3,7 @@ import net.http
const (
write_set_cookie_tests = [
ReadSetCookiesTestCase{
header: map{
header: {
'Set-Cookie': ['special-7=","']
}
cookies: [

View File

@ -1,9 +1,9 @@
fn main() {
_ := []int{len: 10, cap: 10, init: 7}
_ := []map[string]string{len: 5, cap: 50, init: map{
_ := []map[string]string{len: 5, cap: 50, init: {
'a': 'a'
}}
_ := []map[string][]int{len: 7, cap: 100, init: map{
_ := []map[string][]int{len: 7, cap: 100, init: {
'a': [1, 2]
}}
}

View File

@ -70,7 +70,7 @@ fn linebreaks_in_ascii_art_block_comments() {
}
fn map_comments() {
mymap := map{
mymap := {
// pre
`:`: 1
`!`: 2 // after

View File

@ -80,7 +80,7 @@ fn no_empty_lines() {
mut files := map[string][]FileData{}
code := 'foo
bar'
params[0] = {
params[0] = IfExpr{
...params[0]
typ: params[0].typ.set_nr_muls(1)
}

View File

@ -9,7 +9,7 @@ pub struct Foo {
}
pub fn (f Foo) new_some<T>(value T) Optional<T> {
return {
return Optional{
value: value
some: true
}

View File

@ -22,8 +22,8 @@ fn main() {
y: 0
}
)
bar2_func({})
bar2_func({ x: 's' },
bar2_func()
bar2_func(Bar{ x: 's' },
x: 's'
)
baz_func('foo', 'bar',
@ -32,7 +32,7 @@ fn main() {
)
ui.row(
// stretch: true
margin: {
margin: Margin{
top: 10
left: 10
right: 10

View File

@ -16,15 +16,15 @@ fn main() {
x: 0
y: 0
})
bar2_func({})
bar2_func({x: 's'}, {x: 's'})
bar2_func()
bar2_func(Bar{x: 's'}, x: 's')
baz_func('foo', 'bar', x: 0
y: 0
)
ui.row({
ui.row(
//stretch: true
margin: {top:10,left:10,right:10,bottom:10}
})
margin: Margin{top:10,left:10,right:10,bottom:10}
)
}
fn bar_func(bar Bar) {

View File

@ -52,6 +52,5 @@ fn main() {
}
fn trailing_struct_with_update_expr() {
c.error('duplicate const `$field.name`', { ...field.pos, len: name_len })
c.error('duplicate const `$field.name`', Position{ ...field.pos, len: name_len })
}

View File

@ -28,7 +28,7 @@ struct Struct {
}
fn (s Struct) method(v StructMethodArg) StructMethodRet {
return {}
return StructMethodRet{}
}
interface Interface {
@ -43,7 +43,7 @@ fn f(v FnArg) FnRet {
println(Enum.val)
return {}
return FnRet{}
}
struct App {

View File

@ -33,7 +33,7 @@ struct Struct {
}
fn (s Struct) method(v StructMethodArg) StructMethodRet {
return {}
return StructMethodRet{}
}
interface Interface {
@ -47,7 +47,7 @@ fn f(v FnArg) FnRet {
println(Enum.val)
return {}
return FnRet{}
}
struct App {

View File

@ -1,5 +1,5 @@
const (
reserved_types = map{
reserved_types = {
'i8': true
'i16': true
'int': true
@ -8,7 +8,7 @@ const (
}
)
numbers := map{
numbers := {
'one': 1
'two': 2
'sevenhundredseventyseven': 777

View File

@ -5,11 +5,11 @@ fn workaround() {
fn main() {
mut ams := []map[string]string{}
ams << map{
ams << {
'a': 'b'
'c': 'd'
}
ams << map{
ams << {
'e': 'f'
'g': 'h'
}

View File

@ -5,7 +5,7 @@ fn sqr(n int) int {
fn main() {
fns := [sqr]
println(fns[0](10))
fns_map := map{
fns_map := {
'sqr': sqr
}
println(fns_map['sqr'])

View File

@ -73,8 +73,6 @@ fn main() {
println('key' in m)
print('true\t=> ')
println('badkey' !in m)
print('true\t=> ')
println('o' in 'hello')
// for in
for _ in arr1 {}

View File

@ -71,7 +71,7 @@ fn main() {
arr := [1, 2, 3, 4, 5]
for i in arr {
}
ma := map{
ma := {
'str': 'done'
'ddo': 'baba'
}

View File

@ -50,6 +50,8 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
p.inside_match = false
} else if p.tok.lit == 'map' && p.peek_tok.kind == .lcbr && !(p.builtin_mod
&& p.file_base in ['map.v', 'map_d_gcboehm_opt.v']) {
p.warn_with_pos("deprecated map syntax, use syntax like `{'age': 20}`",
p.tok.position())
p.next() // `map`
p.next() // `{`
node = p.map_init()
@ -297,33 +299,9 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
}
}
.lcbr {
// TODO: remove this when deprecation will be removed, vfmt should handle it for a while
// Map `{"age": 20}` or `{ x | foo:bar, a:10 }`
// Map `{"age": 20}`
p.next()
if p.tok.kind in [.chartoken, .number, .string] {
p.warn_with_pos("deprecated map syntax, use syntax like `map{'age': 20}`",
p.prev_tok.position())
node = p.map_init()
} else {
// it should be a struct
if p.tok.kind == .name && p.peek_tok.kind == .pipe {
// TODO: remove deprecated
p.warn_with_pos('use e.g. `...struct_var` instead', p.peek_tok.position())
node = p.assoc()
} else if (p.tok.kind == .name && p.peek_tok.kind == .colon)
|| p.tok.kind in [.rcbr, .comment, .ellipsis] {
node = p.struct_init(true) // short_syntax: true
p.warn_with_pos('short struct initalization is deprecated, use explicit struct name',
node.position())
} else if p.tok.kind == .name {
p.next()
return p.error_with_pos('unexpected $p.tok, expecting `:` after struct field name',
p.tok.position())
} else {
return p.error_with_pos('unexpected $p.tok, expecting struct field name',
p.tok.position())
}
}
node = p.map_init()
p.check(.rcbr)
}
.key_fn {

View File

@ -1,6 +1,6 @@
vlib/v/parser/tests/for_in_mut_key_of_map.vv:3:6: error: index of array or key of map cannot be mutated
1 | fn main() {
2 | mut m := map{'foo': 1, 'bar': 2}
2 | mut m := {'foo': 1, 'bar': 2}
3 | for mut k, _ in m {
| ~~~
4 | println(k)

View File

@ -1,5 +1,5 @@
fn main() {
mut m := map{'foo': 1, 'bar': 2}
mut m := {'foo': 1, 'bar': 2}
for mut k, _ in m {
println(k)
}

View File

@ -7,7 +7,7 @@ fn test_array_or() {
}
fn test_map_or() {
m := map{
m := {
'as': 3
'qw': 4
'kl': 5

View File

@ -1,7 +1,7 @@
vlib/v/parser/tests/struct_field_expected.vv:6:2: error: unexpected token `.`, expecting struct field name
4 |
5 | x = {
6 | .a : 'Alpha'
| ^
7 | .b : 'Beta'
8 | }
vlib/v/parser/tests/struct_field_expected.vv:6:4: error: invalid expression: unexpected token `:`
4 |
5 | x = Bar{
6 | .a: 'Alpha'
| ^
7 | .b: 'Beta'
8 | }

View File

@ -2,8 +2,8 @@ enum TestEnum {
a b
}
x = {
.a : 'Alpha'
.b : 'Beta'
x = Bar{
.a: 'Alpha'
.b: 'Beta'
}

View File

@ -55,7 +55,7 @@ fn test_samples() {
assert x.cflags == ['-I/usr/include', '-pthread', '-I/usr/include/glib-2.0',
'-I/usr/lib/x86_64-linux-gnu/glib-2.0/include',
]
assert x.vars == map{
assert x.vars == {
'prefix': '/usr'
'libdir': '/usr/lib/x86_64-linux-gnu'
'includedir': '/usr/include'
@ -74,7 +74,7 @@ fn test_samples() {
assert x.libs_private == ['-pthread']
assert x.cflags == ['-I/usr/include/glib-2.0',
'-I/usr/lib/x86_64-linux-gnu/glib-2.0/include', '-I/usr/include']
assert x.vars == map{
assert x.vars == {
'prefix': '/usr'
'libdir': '/usr/lib/x86_64-linux-gnu'
'includedir': '/usr/include'

View File

@ -1,7 +1,7 @@
import geometry
fn test_aliases_map_init() {
a := geometry.ShapeMap(map{
a := geometry.ShapeMap({
geometry.Shape.circle: 'Shape is a circle.'
})
assert a[geometry.Shape.circle] == 'Shape is a circle.'

View File

@ -1,14 +1,14 @@
type Map = map[string]string
pub fn new_map() Map {
return Map(map{
return Map({
'23': 'str'
})
}
fn (a Map) + (b Map) Map {
str := b['23']
return Map(map{
return Map({
'34': str + '12'
})
}
@ -16,7 +16,7 @@ fn (a Map) + (b Map) Map {
fn test_map_alias_op_overloading() {
a := new_map()
b := new_map()
assert a + b == Map(map{
assert a + b == Map({
'34': 'str12'
})
assert '${a + b}' == "Map({'34': 'str12'})"

View File

@ -1,5 +1,5 @@
fn test_anon_fn_in_map() {
mut woop := map{
mut woop := {
'what': fn () string {
return 'whoopity whoop'
}

View File

@ -4,7 +4,7 @@ struct Page {
fn test_array_append_short_struct() {
mut pages := []Page{}
pages << {
pages << Page{
contents: 3
}
println(pages)

View File

@ -32,7 +32,7 @@ fn test_array_or_direct() {
}
fn test_map_or() {
m := map{
m := {
'as': 3
'qw': 4
'kl': 5
@ -52,7 +52,7 @@ fn test_map_or() {
}
fn get_map_el(key string) ?int {
m := map{
m := {
'as': 3
'qw': 4
'kl': 5

View File

@ -8,13 +8,13 @@ fn (a Num) < (b Num) bool {
fn test_sort_lt_overloaded_struct_array() {
mut arr := []Num{}
arr << {
arr << Num{
value: 10
}
arr << {
arr << Num{
value: 5
}
arr << {
arr << Num{
value: 7
}
arr.sort()

View File

@ -45,11 +45,11 @@ fn test_interpolation_array_to_string() {
fn test_interpolation_array_of_map_to_string() {
mut ams := []map[string]string{}
ams << map{
ams << {
'a': 'b'
'c': 'd'
}
ams << map{
ams << {
'e': 'f'
'g': 'h'
}

View File

@ -115,7 +115,7 @@ fn test_nested_for_in_array_both() {
}
const (
m = map{
m = {
'key': 'value'
}
)

View File

@ -1,7 +1,7 @@
import json
fn test_calling_functions_with_map_initializations_containing_arrays() {
result := json.encode(map{
result := json.encode({
// NB: []string{} should NOT be treated as []json.string{}
'users': []string{}
'groups': []string{}

View File

@ -26,7 +26,7 @@ fn test_cross_assign_of_array_in_fn() {
// Test cross assign of map values
fn test_cross_assign_of_map() {
mut a := map{
mut a := {
'one': 1
'two': 2
}
@ -42,7 +42,7 @@ fn foo2(mut a map[string]int) {
}
fn test_cross_assign_of_map_in_fn() {
mut a := map{
mut a := {
'one': 1
'two': 2
}
@ -94,7 +94,7 @@ fn test_cross_assign_of_struct_in_fn() {
// Test cross assign of mixed types
fn test_cross_assign_of_mixed_types() {
mut a := [0, 1]
mut m := map{
mut m := {
'one': 1
'two': 2
}
@ -119,7 +119,7 @@ fn foo(mut a []int, mut m map[string]int, mut x Zoo) {
fn test_cross_assign_of_mixed_types_in_fn() {
mut a := [0, 1]
mut m := map{
mut m := {
'one': 1
'two': 2
}
@ -140,7 +140,7 @@ fn test_cross_assign_of_mixed_types_in_fn() {
// Test cross assign of complex types
fn test_cross_assign_of_complex_types() {
mut a := [0, 1]
mut m := map{
mut m := {
'one': 1
'two': 2
}

View File

@ -18,7 +18,7 @@ fn test_fn_array_direct_call() {
}
fn test_fn_map_direct_call() {
a := map{
a := {
'aaa': fn () string {
return 'aaa'
}

View File

@ -12,7 +12,7 @@ fn test_fn_mut_args_of_array() {
}
fn init_map(mut n map[string]int) {
n = map{
n = {
'one': 1
}
}
@ -21,7 +21,7 @@ fn test_fn_mut_args_of_map() {
mut m := map[string]int{}
init_map(mut m)
println(m)
assert m == map{
assert m == {
'one': 1
}
}

View File

@ -64,7 +64,7 @@ fn test_for_in_fixed_array_of_fixed_array_literal() {
fn test_for_in_map_of_fixed_array() {
mut rets := []string{}
m := map{
m := {
'aa': [1, 2]!
'bb': [3, 4]!
'cc': [5, 6]!
@ -82,7 +82,7 @@ fn test_for_in_map_of_fixed_array() {
fn test_for_in_map_of_fixed_array_literal() {
mut rets := []string{}
for k, v in map{
for k, v in {
'aa': [1, 2]!
'bb': [3, 4]!
'cc': [5, 6]!
@ -97,7 +97,7 @@ fn test_for_in_map_of_fixed_array_literal() {
fn test_for_mut_in_map_of_fixed_array() {
mut rets := []string{}
mut m := map{
mut m := {
'aa': [1, 2]!
'bb': [3, 4]!
'cc': [5, 6]!

View File

@ -31,7 +31,7 @@ fn foo3(mut m map[string][3]int) {
}
fn test_fn_mut_val_of_map() {
mut m := map{
mut m := {
'hello': [1, 2, 3]!
}
foo3(mut m)
@ -46,7 +46,7 @@ fn foo4(mut m map[string][3]int) {
}
fn test_for_in_mut_val_of_map() {
mut m := map{
mut m := {
'hello': [1, 2, 3]!
}
foo4(mut m)
@ -55,7 +55,7 @@ fn test_for_in_mut_val_of_map() {
}
fn test_for_in_mut_val_of_map_direct() {
mut m := map{
mut m := {
'foo': 1
'bar': 2
}
@ -67,16 +67,16 @@ fn test_for_in_mut_val_of_map_direct() {
}
fn test_for_in_mut_val_of_map_fixed_array() {
mut m := map{
'foo': [map{
mut m := {
'foo': [{
'a': 1
}]!
'bar': [map{
'bar': [{
'b': 2
}]!
}
for _, mut j in m {
j = [map{
j = [{
'c': 3
}]!
}

View File

@ -62,7 +62,7 @@ fn test_for_in_fixed_array_label_continue_break() {
fn test_for_in_map_label_continue_break() {
mut rets := []string{}
m := map{
m := {
'a': 4
'b': 5
'c': 6

View File

@ -44,7 +44,7 @@ fn test_for_char_in_string() {
}
fn test_for_string_in_map() {
m := map{
m := {
'a': 'b'
'c': 'd'
}
@ -54,7 +54,7 @@ fn test_for_string_in_map() {
}
assert acc == 'a: b, c: d, '
mut m2 := map{
mut m2 := {
'a': 3
'b': 4
'c': 5

View File

@ -4,32 +4,32 @@ fn print_map<K, V>(x map[K]V) string {
}
fn test_generics_infer_map_type() {
m1 := map{
m1 := {
'one': 1
}
assert print_map(m1) == "{'one': 1}"
m2 := map{
m2 := {
'one': 1.1
}
assert print_map(m2) == "{'one': 1.1}"
m3 := map{
m3 := {
'one': 'a'
}
assert print_map(m3) == "{'one': 'a'}"
m4 := map{
m4 := {
1: 'one'
}
assert print_map(m4) == "{1: 'one'}"
m5 := map{
m5 := {
1.1: 'one'
}
assert print_map(m5) == "{1.1: 'one'}"
m6 := map{
m6 := {
'a': 'one'
}
assert print_map(m6) == "{'a': 'one'}"

View File

@ -41,7 +41,7 @@ fn test_generic_fn_infer_multi_paras() {
page: 'one'
var_one: 'variable one'
var_two: 'variable two'
var_three: {
var_three: Two_data{
title: 'what a title'
content: 'what a content'
}

View File

@ -6,7 +6,7 @@ mut:
}
pub fn new_some<T>(value T) Optional<T> {
return {
return Optional{
value: value
some: true
}
@ -40,7 +40,7 @@ pub struct Foo {
}
pub fn (f Foo) new_some<T>(value T) Optional<T> {
return {
return Optional{
value: value
some: true
}

View File

@ -7,7 +7,7 @@ mut:
}
pub fn new_some<T, B>(value T, b B) Optional<T> {
return {
return Optional{
value: value
some: true
typ: typeof(b).name
@ -54,7 +54,7 @@ pub struct Foo {
}
pub fn (f Foo) new_some<T, B>(value T, b B) Optional<T> {
return {
return Optional{
value: value
some: true
typ: typeof(b).name

View File

@ -5,7 +5,7 @@ mut:
}
fn new_foo<A, B>(a A, b B) Foo<A, B> {
return {
return Foo{
a: a
b: b
}

View File

@ -11,7 +11,7 @@ fn test_identity() {
assert simple<string>('g') + 'h' == 'gh'
assert simple<[]int>([1])[0] == 1
assert simple<map[string]string>(map{
assert simple<map[string]string>({
'a': 'b'
})['a'] == 'b'
@ -399,7 +399,7 @@ fn test_pass_generic_to_nested_function() {
}
fn generic_return_map<M>() map[string]M {
return map{
return {
'': M{}
}
}
@ -409,8 +409,8 @@ fn test_generic_return_map() {
}
fn generic_return_nested_map<M>() map[string]map[string]M {
return map{
'': map{
return {
'': {
'': M{}
}
}

View File

@ -26,7 +26,7 @@ fn test_fn_return_empty() {
}
fn test_map_get() {
mut m := map{
mut m := {
'xy': 5
'zu': 7
}
@ -42,7 +42,7 @@ fn test_map_get() {
}
fn test_map_get_empty() {
mut m := map{
mut m := {
'xy': 5
'zu': 7
}

View File

@ -115,7 +115,7 @@ fn test_in_expression_in_alias() {
assert 0 in arr
assert 100 !in arr
m := MapAlias(map{
m := MapAlias({
'one': 1
'two': 2
'three': 3
@ -125,7 +125,7 @@ fn test_in_expression_in_alias() {
}
fn test_in_expression_in_map() {
m := map{
m := {
'one': 1
'two': 2
'three': 3
@ -134,14 +134,6 @@ fn test_in_expression_in_map() {
assert 'four' !in m
}
fn test_in_expression_in_string() {
s := 'abcd'
assert 'a' in s
assert 'ab' in s
assert 'abcd' in s
assert 'dbca' !in s
}
fn test_optimized_in_expression() {
mut a := false
a = true && 2 in [1, 2]

View File

@ -69,7 +69,7 @@ __global (
testexpl = f32(7)
testfn = get_u64()
testarr = []f64{len: 10, init: 2.75}
testmap = map{
testmap = {
'qwe': 2.5
'asd': -7.25
'yxc': 3.125

Some files were not shown because too many files have changed in this diff Show More