tools.analyzer

Tests written using simple-check might be problematic for tools.analyzer

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Discovered when trying to use the latest version of tools.analyzer(.jvm) and Eastwood on the automat library: https://github.com/ztellman/automat

I do not yet know whether this will be true of any project that uses simple-check for tests. I will add more to this description if I find other examples.

Below is the error message I see when running 'lein eastwood' in automat's project root dir:

== Linting automat.core-simple-check ==
Exception thrown during phase :analyze of linting namespace automat.core-simple-chec
k
Got exception with extra ex-data:
    msg='No such namespace: simple-check.core'
    (keys dat)=(:ns)
ExceptionInfo No such namespace: simple-check.core
        clojure.core/ex-info (core.clj:4327)
        clojure.tools.analyzer.passes.jvm.validate/eval1616/fn--1618 (validate.clj:3
3)

automat requires the namespaces simple-check.clojure-test, which defines a macro defspec that contains (require 'simple-check.core) here: https://github.com/reiddraper/simple-check/blob/master/src/simple_check/clojure_test.clj#L28

along with a comment mentioning that this is a cyclic dependency.

This may be beyond what is reasonable to expect tools.analyzer(.jvm) to be able to handle, but wanted to get the example to you in case not.

Activity

Hide
Nicola Mometto added a comment -

It looks like it's an instance of the Gilardi Scenario.

There's nothing that can be done to fix this in the analyzer as a "fix" for this requires breaking up do expression and evaluating them piece by piece instead of analyzing the entire do form and evaluating it all in a single step.

This is how tools.emitter.jvm does it: https://github.com/clojure/tools.emitter.jvm/blob/master/src/main/clojure/clojure/tools/emitter/jvm.clj#L19-L26

Show
Nicola Mometto added a comment - It looks like it's an instance of the Gilardi Scenario. There's nothing that can be done to fix this in the analyzer as a "fix" for this requires breaking up do expression and evaluating them piece by piece instead of analyzing the entire do form and evaluating it all in a single step. This is how tools.emitter.jvm does it: https://github.com/clojure/tools.emitter.jvm/blob/master/src/main/clojure/clojure/tools/emitter/jvm.clj#L19-L26
Hide
Andy Fingerhut added a comment -

So a question: Does such a construct become illegal in a future CinC implementation? I'm not arguing that it should become illegal, or should not, but if it should, it might be a good idea to mention it to the simple-check authors, and/or more Clojure devs.

Show
Andy Fingerhut added a comment - So a question: Does such a construct become illegal in a future CinC implementation? I'm not arguing that it should become illegal, or should not, but if it should, it might be a good idea to mention it to the simple-check authors, and/or more Clojure devs.
Hide
Nicola Mometto added a comment -

I might have explained myself badly here.
tools.analyzer's behaviour in this case is exatly the same as clojure's one, and indeed clojure will fail on that expression too if all you do is call clojure.lang.Compiler/analyze on it.

clojure can eval that expression because it will analyze & eval all the do forms separately – this is what tools.emitter.jvm does too.

if we want to analyze this expression in eastwood we need to manually analyze do forms separately too.

Show
Nicola Mometto added a comment - I might have explained myself badly here. tools.analyzer's behaviour in this case is exatly the same as clojure's one, and indeed clojure will fail on that expression too if all you do is call clojure.lang.Compiler/analyze on it. clojure can eval that expression because it will analyze & eval all the do forms separately – this is what tools.emitter.jvm does too. if we want to analyze this expression in eastwood we need to manually analyze do forms separately too.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: