core-typed

Olical 2025-05-26T20:25:36.601949Z

Does anyone have a clj-kondo config that helps it understand defalias? I tried to use lint-as def but it didn't seem to help 🤔

Olical 2025-05-28T10:18:23.803019Z

It's probably that import line, thanks! I must have missed that in the docs. I am just seeing my aliases not being valid symbols when used later, clj-kondo doesn't realise defalias binds something that that symbol. Even when I configured defalias to mean def which is interesting.

Olical 2025-05-28T10:20:59.728489Z

Huh, even with the configs in .clj-kondo, I still see an error here. Probably still user error, sorry about the screenshot...

2025-05-28T14:22:05.570779Z

No that's legit. Not sure what to do about that.

2025-05-28T14:22:34.685309Z

It's a false negative in general since clojure doesn't resolve symbols there. cljs might.

2025-05-28T14:25:42.140099Z

This horrible hack should suppress the warning ^{::t/unsafe-cast ^:fake-quote 'TypedClojureExInfoData} . I think either clj-kondo needs to tighten its rules about metadata, or the defalias hook needs to register fake vars during clj-kondo so they can be resolved.

2025-05-28T14:26:08.237999Z

the latter might have nice side benefits like jump-to-definition

borkdude 2025-05-28T21:57:29.431349Z

> It's a false negative in general since clojure doesn't resolve symbols there. cljs might. can you give an example of this as a standalone snippet?

2025-05-29T02:52:51.347569Z

@borkdude this is Typed Clojure living on the edge, but sure: The first 3 are false negatives and the last is a true negative (using https://clj-kondo.michielborkent.nl/):

^{:foo (a)} identity
^{:foo (ab)} (identity 1)
^{:foo (abc)} (:foo {})
^{:foo (abcd)} (fn [])

2025-05-29T02:55:15.294369Z

AFAICT metadata on symbols and non-macro calls in expression position are never evaluated in Clojure (they're quoted). Some macros have special handling of &form meta like -> and fn.

2025-05-29T02:56:49.162209Z

These are more false negatives AFAICT:

(let [^{:foo (a)} foo identity] foo)
(fn [^{:foo (aa)} foo] foo)
(fn ^{:foo (bar)} [])
^{:foo (bar)} (do)
(fn ^{:foo (bar)} a [])
(let [a 1] ^{:foo (a)} a)
(fn [a] ^{:foo (ab)} a)

2025-05-29T02:57:55.784809Z

There's something that's inconsistent between clj and cljs but I can't remember what. Maybe it's metadata passed to def or defn. One is evaluated the other is quoted. EDIT: it's this:

^{:foo (bar)} (defn a [])
Error in cljs, but fine in clj. clj-kondo says error.

borkdude 2025-05-29T08:10:54.754999Z

> The first 3 are false negatives Do you mean false positive?

borkdude 2025-05-29T08:12:28.703059Z

false negative is when something that should be reported isn't reported

borkdude 2025-05-29T08:13:07.757429Z

anyway, perhaps clj-kondo could do a better job of not warning about this, but then again, cases like this do evaluate the metadata:

user=> ^{:foo (a)} {}
Syntax error compiling at (REPL:1:8).
Unable to resolve symbol: a in this context

2025-05-29T14:42:44.473939Z

yes false positive

2025-05-29T14:51:05.975169Z

it's context sensitive, fn also evaluates

borkdude 2025-05-29T14:51:55.530669Z

yes

borkdude 2025-05-29T14:52:16.993749Z

I know since I had to implement all of that in SCI 😅

😁 1
2025-05-29T14:52:49.540919Z

that's why it's not a great idea in the first place. it's pretty useful given how typed clojure works, but I don't blame you if you don't want to wander into this undocumented area.

👍 1
borkdude 2025-05-29T14:54:25.888169Z

recently I had a nice bug in bb + meander. meander stored stuff in the type :tag , like & which wasn't a class. bb evaluated that a bit too early (which caused an unresolved symbol). clojure only evaluates :tag (in the compiler) when it encounters an interop form

👏 1
2025-05-29T16:05:14.741609Z

Oh, there might be a quick and isolated solution to this if you're willing to do something Typed Clojure-specific. The next version has type checking opt-in via (ns ^:typed.clojure foo) . Basically you know you're in a Typed Clojure file if (-> *ns* meta (contains? :typed.clojure)) is true. My idea was to have clj-kondo default to assuming metadata is not evaluated if you're in a Typed Clojure file. Other quick solutions might be to ignore the value of :typed.clojure qualified keywords in meta maps.

2025-05-29T16:06:44.646579Z

I can also help with a real solution if you want to support this for real.

2025-05-28T00:17:59.368089Z

it should work out of the box

2025-05-28T00:18:12.827909Z

what is the warning you're seeing?

2025-05-28T00:19:16.941159Z

you might need to import the rules, they're packaged in one of the typed clojure jars

2025-05-28T00:20:00.127839Z

something like clj-kondo --lint "$(clojure -Spath)" --copy-configs --skip-lint

2025-05-28T00:20:45.198689Z

maybe the :dev alias also needs including