Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #16650 #16660

Merged
merged 1 commit into from
Jan 10, 2021
Merged

fix #16650 #16660

merged 1 commit into from
Jan 10, 2021

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Jan 10, 2021

fix #16650

when defined case1:
  template fn() =
    echo len(cstring"ab\0c") # ok: \0 is escaped, like r"ab\0c")
    echo len(cstring("ab\0c")) # bug
    let c = cstring("ab\0c") # ok
    echo len(c)
  fn()
  static: fn()

Before:

VM:
5
4
4

RT:
5
4
2

After

VM:
5
4
2

RT:
5
2
2

@@ -108,13 +104,22 @@ bar(nilstring)
static:
stringCompare()

# bug 8847
# issue #8847
Copy link
Member

@timotheecour timotheecour Jan 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://nim-lang.github.io/Nim/contributing.html

Always refer to a GitHub issue using the following exact syntax: bug #1234 as shown above, so that it's consistent and easier to search or for tooling. [...]

ditto below

doAssert len(cstring"ab\0c") == 5
doAssert len(cstring("ab\0c")) == 2
when nimvm:
discard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
discard
discard # pending bug #16555

if a.typ.kind == tyString:
result = newIntNodeT(toInt128(a.strVal.len), n, g)
elif a.typ.kind == tyCString:
result = newIntNodeT(toInt128(nimCStrLen(a.strVal)), n, g)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result = newIntNodeT(toInt128(nimCStrLen(a.strVal)), n, g)
result = newIntNodeT(toInt128(nimCStrLen(a.strVal)), n, g)
else: assert(0)

@cooldome cooldome merged commit 2c6f5ae into nim-lang:devel Jan 10, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

len(cstring("ab\0c")) is 4 instead of 2
3 participants