Externs inference for singletons fails - i.e (has-extern? '[crypto subtle]) => false

Description

Work on https://clojure.atlassian.net/jira/software/c/projects/CLJS/issues/CLJS-3425?jql=project%20%3D%20%22CLJS%22%20ORDER%20BY%20created%20DESC has revealed deeper issues with externs inference. Inference on singletons in the global namespace simply doesn’t work. The currently algorithm is instance-centric in the sense that it mostly works when users instantiate some type, or gets an instance of a type from some API and uses it. But it completely fails in cases like crypto.subtle. In order to know that this has an extern we have to see that crypto has type {!webCrypto.Crypto|undefined} (note this is not parsed correctly at the moment). Then we need to look at the prototype to find the subtle property, then we need to look up the type of subtle for externs inference to proceed correctly.

The Number.isNaN case is related in that we infer Number to be of type Function and this is why we don’t correctly infer the return type of isNaN calls.

Environment

None

Activity

Show:

David NolenFebruary 17, 2025 at 5:12 PM

A review of has-extern? and js-tag has show that this code ripe for a bit of refactoring. At the very least they should probably share resolution logic (which they don’t currently)

Details

Assignee

Reporter

Priority

Created February 17, 2025 at 5:06 PM
Updated March 19, 2025 at 3:33 PM