summaryrefslogtreecommitdiff
path: root/tests/typ/bugs/3154-array-dict-mut-entry.typ
blob: b5a52814bb8836e3341816181fe8eb3cf384ac42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Issue #3154: Confusing errors from methods supposed to return a mutable entry
// https://github.com/typst/typst/issues/3154
// Ref: false

---
#{
  let array = ()
  // Error: 3-16 array is empty
  array.first()
}

---
#{
  let array = ()
  // Error: 3-16 array is empty
  array.first() = 9
}

---
#{
  let array = ()
  // Error: 3-15 array is empty
  array.last()
}

---
#{
  let array = ()
  // Error: 3-15 array is empty
  array.last() = 9
}

---
#{
  let array = (1,)
  // Error: 3-14 array index out of bounds (index: 1, len: 1) and no default value was specified
  array.at(1)
}

---
#{
  let array = (1,)
  test(array.at(1, default: 0), 0)
}

---
#{
  let array = (1,)
  // Error: 3-14 array index out of bounds (index: 1, len: 1)
  array.at(1) = 9
}

---
#{
  let array = (1,)
  // Error: 3-26 array index out of bounds (index: 1, len: 1)
  array.at(1, default: 0) = 9
}

---
#{
  let dict = (a: 1)
  // Error: 3-15 dictionary does not contain key "b" and no default value was specified
  dict.at("b")
}

---
#{
  let dict = (a: 1)
  test(dict.at("b", default: 0), 0)
}

---
#{
  let dict = (a: 1)
  // Error: 3-15 dictionary does not contain key "b"
  // Hint: 3-15 use `insert` to add or update values
  dict.at("b") = 9
}

---
#{
  let dict = (a: 1)
  // Error: 3-27 dictionary does not contain key "b"
  // Hint: 3-27 use `insert` to add or update values
  dict.at("b", default: 0) = 9
}

---
#{
  let dict = (a: 1)
  // Error: 8-9 dictionary does not contain key "b"
  dict.b
}

---
#{
  let dict = (a: 1)
  dict.b = 9
  test(dict, (a: 1, b: 9))
}

---
#{
  let dict = (a: 1)
  // Error: 3-9 dictionary does not contain key "b"
  // Hint: 3-9 use `insert` to add or update values
  dict.b += 9
}