shadow-cljs

2025-01-24T19:35:32.011179Z

This is a weird one! Given a test like the following:

(is (thrown? :default (subs nil 1 2)))
I expect that to pass. If I run shadow-cljs watch test where :test refers to my build entry, it passes as expected. If I run:
shadow-cljs release test
node target/js/node-tests.js
The assertion fails with the assertion:
FAIL in (test-subs) (clojure/core_test/subs.cljc:20:14)
expected: (thrown? :default (subs nil 1 2))
  actual: nil
Any thoughts as to what's causing that? I'm using the default cljs test runner

2025-01-25T08:29:09.639009Z

Narrowed it down to :optimizations :simple vs :optimizations :advanced

2025-01-25T08:39:45.470649Z

Narrowed it down further, the :advanced optimization is inlining the tests calling subs to "string".substring(x, y), but in the case of (subs nil 1 2), I think the google closure compiler is factoring it out as it knows null.substring(1, 2) is not valid code

2025-01-25T08:40:28.561839Z

I think that confirms this is not an issue with shadow, likely just a side-effect from the google closure compiler

🚒 1
thheller 2025-01-25T09:48:26.462229Z

interesting. is there no compiler error/warning at all? what is left in the code?

2025-01-25T13:53:40.111629Z

Correct, no warning or error from the compiler. I’ll create a mini reproduction repo. Unfortunately, it’s unclear precisely what the code compiles to right now https://media.discordapp.net/attachments/1332619461026648065/1332628554797813780/CleanShot_2025-01-25_at_03.29.462x.png?ex=6795f28e&is=6794a10e&hm=a413119901cf5f143c4cc1748417a2fc99accc5e82668f7e596da8509dd0f782& But based on the error we get in ci it seems (is (thrown? (subs nil 1 2))) is optimized to something like (is (thrown? nil)) which causes that test to fail.

2025-01-25T17:03:29.611009Z

Here's a very minimal reproduction repo