-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: show that
{j| ... |j}
with interpolation doesn't typecheck
- Loading branch information
1 parent
83a0ed8
commit 6aa3f8e
Showing
1 changed file
with
43 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,56 @@ | ||
|
||
$ . ./setup.sh | ||
$ cat > dune-project <<EOF | ||
> (lang dune 3.8) | ||
> (using melange 0.1) | ||
> EOF | ||
$ cat > dune <<EOF | ||
> (melange.emit | ||
> (target output) | ||
> (alias mel) | ||
> (preprocess (pps melange.ppx))) | ||
> EOF | ||
$ cat > x.ml <<EOF | ||
> let () = Format.printf {js|你 %s|js} "xx" | ||
> let () = Js.log (Format.sprintf {js|你 %s|js} "xx") | ||
> EOF | ||
$ melc -ppx melppx x.ml | ||
$ dune build @mel | ||
$ cat _build/default/output/x.js | ||
// Generated by Melange | ||
'use strict'; | ||
var Curry = require("melange.js/curry.js"); | ||
var Stdlib__Format = require("melange/format.js"); | ||
Curry._1(Stdlib__Format.printf(/* Format */{ | ||
_0: { | ||
TAG: /* String_literal */11, | ||
_0: "你 ", | ||
_1: { | ||
TAG: /* String */2, | ||
_0: /* No_padding */0, | ||
_1: /* End_of_format */0 | ||
} | ||
}, | ||
_1: "你 %s" | ||
}), "xx"); | ||
console.log(Curry._1(Stdlib__Format.sprintf(/* Format */{ | ||
_0: { | ||
TAG: /* String_literal */11, | ||
_0: "你 ", | ||
_1: { | ||
TAG: /* String */2, | ||
_0: /* No_padding */0, | ||
_1: /* End_of_format */0 | ||
} | ||
}, | ||
_1: "你 %s" | ||
}), "xx")); | ||
/* Not a pure module */ | ||
$ node _build/default/output/x.js | ||
你 xx | ||
Show that `{j| ... |j}` with interpolation doesn't work because string | ||
concatenation isn't a literal | ||
$ cat > x.ml <<EOF | ||
> let x = "xx" | ||
> let () = Js.log (Format.sprintf {j|你 \$(x) %s|j} "xx") | ||
> EOF | ||
$ dune build @mel | ||
File "x.ml", line 1: | ||
Error: This expression has type string but an expression was expected of type | ||
('a -> 'b, unit, string) format = | ||
('a -> 'b, unit, string, string, string, string) format6 | ||
[1] |