Fork me on GitHub
#cljs-dev
<
2024-04-17
>
lilactown00:04:53

I believe I've found a bug in :as-alias when combined with namespaced maps.

$ cat src/app/a.cljs
(ns app.a
  (:require
    [app.b :as-alias b]))

;; works
#_(def data {::b/x 1 ::b/y 2 ::b/z 3})

;; broken
(def data #::b {:x 1 :y 2 :z 3})

$ clj -M --main cljs.main --compile app.a
Unexpected error compiling at (REPL:1).
No namespace: app.b found

Full report at:
/var/folders/28/7xm2frlx1cb_gt4nrscjpttw0000gn/T/clojure-10509037535418893124.edn
full repro here: https://github.com/lilactown/cljs-alias-ns-map-bug

lilactown16:04:26

just realized the repo was private- is public now

dnolen18:04:35

I do wonder if it’s reader bug? haven’t had a chance to look closely

john18:04:29

Seems true for normal :as aliases as well?

john18:04:22

other reader tags are handling a space just fine

john18:04:50

Yeah, clj handles the space just fine for map prefixes

john18:04:26

Well, when you read ::b, you think :this.namespace/b, moreso than :alias.for.b/thing-a-number-of-white-spaces-from-here

john18:04:07

So there's a slight argument for map namespace prefixes being slightly stricter than other reader tags, wrt whitespace

dnolen18:04:31

@john so you’re saying normal :as fails as well and the problem is #::b{...} vs #::b {…} - will update the description if this is what you mean

john18:04:02

That's what I'm thinking, and seeing in the repl I think

john18:04:17

I think that's what @lilactown was getting at

john18:04:38

about the space. I think the as-alias is working without the space

dnolen18:04:10

@bronsa what do you think ^?

bronsa18:04:11

I'm a bit surprised the whitespace would be read into the symbol, but let me have a look

john18:04:40

I'm pretty sure this behavior has always been there

john18:04:49

Don't think it's a regression

john18:04:52

Because I think I've wondered about the above rationale for the stricter syntax in the past

john18:04:55

from working on perc in the past

bronsa18:04:34

I'm struggling to see how #::x{:foo 1} #::x {:foo 1} would be any different tbh. I don't think the whitespace matters, it may be a red herring

john18:04:40

Is the reader tag for namespaced keys being checked prior to the one for catching map namepsace prefixes? If not, then the white space would be forcing a namespaced key read, right?

dnolen18:04:54

hrm actually maybe not the reader - since app.b is resolved in the reported error …

bronsa18:04:33

yeah that's what I'm thinking too

bronsa18:04:06

but they really should produce the same object, so something the reader produces is different -- perharps the meta?

bronsa18:04:20

the whitespace is immaterial during reading

john18:04:03

how do you know you've reached the end of a locally namespaced ::some-key?

dnolen18:04:11

@john which makes it stranger that dropping the space works …

john18:04:47

Maybe the clj one isn't trying to resolve, at the stage it's reading from the reader tag itself

bronsa18:04:14

is there a quick way I can repro in a cljs repl? sorry it's been a while since I've played with cljs

john18:04:45

(ns user
  (:require
   [clojure.edn :as edn]))
(def data #::edn {:x 1 :y 2 :z 3})

john18:04:06

should do it. I just use calva to launch my cljs envs quickly these days

john18:04:12

with shadow

dnolen18:04:00

@bronsa from ClojureScript repo - clj -M -m cljs.main -re node -r

👍 1
dnolen18:04:18

I see the reported error after dropping the forms into the REPL

bronsa18:04:54

weird, I don't O.o

bronsa18:04:02

user=> (def data #::edn {:x 1 :y 2 :z 3})
#'user/data
user=> data
#:clojure.edn{:x 1, :y 2, :z 3}

bronsa18:04:19

ClojureScript 1.11.54

bronsa18:04:32

let me try to upgrade

bronsa18:04:25

same on 1.11.132

john18:04:40

Hmm, I wasn't seeing it in the node repl

bronsa18:04:17

if it's env specific it may point to the problem not being the reader

john18:04:58

ah, I'm on an older version of cljs too

john18:04:05

maybe it is a regression

bronsa18:04:10

@john out of curiosity, in wherever env you can repro, does (def data '#::edn {:x 1 :y 2 :z 3}) make a difference?

p-himik18:04:44

FWIW, can't reproduce the issue with :as and a space with the latest vanilla CLJS with both Node and browser-based REPL. Can reproduce with shadow-cljs 2.28.3 (uses same CLJS version under the hood, 132). Adding a quote doesn't change anything.

p-himik19:04:46

@U05224H0W Pinging you since you might want to know.

bronsa19:04:46

ok I tested removing the whitespace in cljs-alias-ns-map-bug and that doesn't seem to make a difference at least, so we can exclude that.

lilactown19:04:04

yeah I just tested this in that repo

$ clj -M -m cljs.main -re node -r
ClojureScript 1.11.132
cljs.user=> (ns a.b (:require [a.c :as-alias c]))
nil
a.b=> ::c/x
:a.c/x
a.b=> #::c{:x 1}
Syntax error reading source at (REPL:1).
No namespace: a.c found
:x
1
Syntax error reading source at (REPL:1).
<NO_SOURCE_FILE> [line 1, col 2] Unmatched delimiter }.
a.b=>

lilactown19:04:13

can't repro the space issue with :as

clj -M -m cljs.main -re node -r
ClojureScript 1.11.132
cljs.user=> (ns a.b (:require [clojure.edn :as edn]))
nil
a.b=> ::edn/x
:clojure.edn/x
a.b=> #::edn{:x 1}
#:clojure.edn{:x 1}
a.b=> #::edn {:x 1}
#:clojure.edn{:x 1}

john19:04:04

(ns user.core
  (:require [cljs.math :as m]))

::m/hi ;=> :cljs.math/hi
#::cljs.math {:hi :there} ;=> #:cljs.math{:hi :there}
#::cljs.math{:hi :there} ;=> #:cljs.math{:hi :there}
#::m {:hi :there} ;=> {:hi :there}
; No namespace: m found 
#::m{:hi :there} ;=> :there
; No namespace: m found

john19:04:24

So, correction, what I'm seeing is happening regardless of a space, just aliasing in general, hmm.. But I'm seeing different behavior in the vanilla node repl I think

dnolen19:04:01

k thanks all for the extra info

john19:04:21

@bronsa

(def data '#::edn {:x 1 :y 2 :z 3}) ;=> {:x 1, :y 2, :z 3}
; No namespace: edn found
; [line 1, col 2] Unmatched delimiter )

john19:04:49

doesn't even compile, but that map is returned and printed

p-himik19:04:37

How exactly did you check that? What was the command that started your REPL?

john19:04:28

So I just started shadow via calva's "jack-in" command. And then I just evaluated the form in the editor

p-himik19:04:10

Did you see my comment above? Where I could reproduce it only in shadow-cljs but not in vanilla CLJS.

p-himik19:04:29

So if anything, the space-related issue seems to be purely on the shadow-cljs side.

john19:04:49

I did see that. That could well be it. Might need to bring this to shadow-cljs

p-himik19:04:19

Right, that's why I pinged Thomas in that thread.

john19:04:00

Did you try the latest cljs on a vanilla node repl and try it?

p-himik19:04:33

Yes, exactly as my comment mentions.

p-himik19:04:41

> can't reproduce the issue with :as and a space with the latest vanilla CLJS with both Node and browser-based REPL

john19:04:49

ah, looks like Thomas has seen it in the shadow channel and is aware

john19:04:02

so data is still not defined

john19:04:21

So correction, this behavior doesn't appear to be present on 1.10.520