Skip to content

"a".[0] syntax is not working #124

@cometkim

Description

@cometkim

According to the ReScript manual, a string "a" can be converted to char 'a' by .[0]

To convert a String to a Char, use "a".[0]. To convert a Char to a String, use String.make(1, 'a').

but the syntax is not working in ReScript.

>>>> Start compiling
bsb: [1/5] src/Test.ast
FAILED: src/Test.ast

  Syntax error!
  /home/cometkim/Workspace/tmp/rescript-template-test-8/src/Test.res:1:13

  1 │ let a = "a".[0]
  2 │

  I'm not sure what to parse here when looking at "[".


  Syntax error!
  /home/cometkim/Workspace/tmp/rescript-template-test-8/src/Test.res:1:14

  1 │ let a = "a".[0]
  2 │

  consecutive statements on a line must be separated by ';' or a newline

bsb: [2/5] src/App-MyRescriptApp.cmj
FAILED: src/App-MyRescriptApp.cmj

I'm not sure it's a compiler bug or It is just a mistake. I'd like to update the docs to use String.unsafe_get instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions