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

Namespaced constructor fails after upgrading Babashka to 1.0.169 #1502

Closed
alysbrooks opened this issue Feb 24, 2023 · 4 comments
Closed

Namespaced constructor fails after upgrading Babashka to 1.0.169 #1502

alysbrooks opened this issue Feb 24, 2023 · 4 comments

Comments

@alysbrooks
Copy link
Contributor

alysbrooks commented Feb 24, 2023

In Lambda Island URI's test suite, recent versions of Babashka cause it to fail. Here's the error I get:

----- Context ------------------------------------------------------------------
12: (deftest parsing
13:   (testing "happy path"
14:     (are [x y] (= y (uri/parse x))
15:       "http://user:password@example.com:8080/path?query=value#fragment"
16:       (uri/URI. "http" "user" "password" "example.com" "8080" "/path" "query=value" "fragment")
          ^--- Unable to resolve classname: uri/URI
17: 
18:       "/happy/path"
19:       (uri/URI. nil nil nil nil nil "/happy/path" nil nil)
20: 
21:       "relative/path"

It appears to be due to trying to call this constructor with the uri/ prefix. Here are the imports for context:

(ns lambdaisland.uri-test
  (:require ,,,
                [lambdaisland.uri :as uri]           ,,,)
  #?(:clj (:import lambdaisland.uri.URI)))

I also created a small issue reproduction here.

@alysbrooks alysbrooks changed the title Import fails after upgrading Babashka 1.0.169 Namespaced constructor fails after upgrading Babashka to 1.0.169 Feb 24, 2023
@borkdude
Copy link
Collaborator

Thanks, I'll take a look tomorrow

@borkdude
Copy link
Collaborator

Btw you can work around this by using the uri/->Uri var instead of the constructor.

@borkdude
Copy link
Collaborator

It's pretty weird how an import makes the uri/URI. notation work. I wouldn't be too surprised if this was undefined behavior in clojure. If you imported the class, there is no need to add the prefix to uri/URI..

user=> (defrecord Rec [])
user.Rec
user=> (ns foo)
nil
foo=> (alias 'u 'user)
nil
foo=> (u/Rec.)
Syntax error (IllegalArgumentException) compiling new at (REPL:1:1).
Unable to resolve classname: Rec
foo=> (user/Rec.)
Syntax error (IllegalArgumentException) compiling new at (REPL:1:1).
Unable to resolve classname: Rec
foo=> (import 'user.Rec)
user.Rec
foo=> (user/Rec.)
#user.Rec{}
foo=> (Rec.) ;; without prefix
#user.Rec{}
foo=> user/Rec
Syntax error compiling at (REPL:0:0).
No such var: user/Rec

Can you explain what is the reasoning for adding the prefix? Usually qualified symbols with a / in them only refer to vars in namespaces.

@borkdude
Copy link
Collaborator

borkdude commented Feb 25, 2023

Got confirmation from Alex Miller that this is undefined behavior:

Screenshot 2023-02-25 at 14 05 39

I think you should update your test by either removing the alias (just write (Uri. ..) or going through the record constructor var: (uri/->Uri ..). The latter is preferred.

Link to discussion: https://app.slack.com/client/T03RZGPFR/C03S1KBA2/thread/C034FQN490E-1677279501.394609

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

No branches or pull requests

2 participants