binaryage / cljs-oops

ClojureScript macros for convenient native Javascript object access.
Other
351 stars 13 forks source link

ocall interaction with *warn-on-infer* #21

Closed aiba closed 5 years ago

aiba commented 5 years ago

Is it expected that ocall should generate a warning when *warn-on-infer* is enabled?

(ns scratch.core
  (:require [oops.core :refer [ocall]]))

(set! *warn-on-infer* true)

(ocall js/document :getElementById "foo")

Produces compiler warning:

  6  (ocall js/document :getElementById "foo")
     ^--- Cannot infer target type in expression (. fn-126930 call (oops.helpers/unchecked-aget call-info-126931 0) "foo")

Perhaps the oops codegen could typehint the fn-* symbol with ^js/Function?

darwin commented 5 years ago

Ah, good catch. Most of cljs-oops was developed before introduction of *warn-on-infer*. I have never tried to enable it myself.

I would have to look deeper into this because I don't really understand the infer message. If you want to take stab at it, here is the code generation responsible for emitting code for ocall: https://github.com/binaryage/cljs-oops/blob/df9ef052a09fac15dc88099acc8a7a504f47ca50/src/lib/oops/codegen.clj#L378