Skip to content

Commit

Permalink
fix #14157 (#15877)
Browse files Browse the repository at this point in the history
* fix #14157

* Update compiler/jsgen.nim

* add changelog

* Update compiler/jsgen.nim

* Update tests/js/tmodify_cstring.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
  • Loading branch information
ringabout and Araq authored Nov 12, 2020
1 parent 826e629 commit 1f9bf43
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

## Language changes

- The `cstring` doesn't support `[]=` operator in JS backend.



## Compiler changes
Expand Down
4 changes: 4 additions & 0 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,10 @@ proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =
var a, b: TCompRes
var xtyp = mapType(p, x.typ)

# disable `[]=` for cstring
if x.kind == nkBracketExpr and x.len >= 2 and x[0].typ.skipTypes(abstractInst).kind == tyCString:
localError(p.config, x.info, "cstring doesn't support `[]=` operator")

gen(p, x, a)
genLineDir(p, y)
gen(p, y, b)
Expand Down
6 changes: 6 additions & 0 deletions tests/js/tmodify_cstring.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
discard """
errormsg: "cstring doesn't support `[]=` operator"
"""

var x = cstring"abcd"
x[0] = 'x'

0 comments on commit 1f9bf43

Please sign in to comment.