clojure.tools.analyzer.passes.jvm/validate throws an exception when :tag metadata cannot be resolved to a Class

Description

While the Clojure Compiler silently ignores :tag metadata in some forms when it cannot be resolved to a class, c.t.a.passes.jvm/validate throws an exception every time.

Some libraries (test.generators) use :tag metadata to store instructions for generating test input data, those can be everything, from symbols to quoted clojure expressions – the Clojure Compiler allows for this but validate throws an exception.

Generally however, when :tag cannot be resolved to a class it's not beacause of a design choice, but because of a Clojure bug or a user-code bug.

Some examples are:

  • tagging a defn form in the fn name with a primitive type hint:

A clojure-dev post has been opened asking whether tools.analyzer.jvm is correct in assuming that non class-resolvible tags are an error and thus an exception could be thrown, or if the current behaviour of the Cloure implementation of throwing in some special places and silently ignoring malformed :tag values is by design. It hasn't have received an official reply yet. https://groups.google.com/d/msg/clojure-dev/hRZFuaiB_50/mzKLirgZWmUJ

Environment

None

Activity

Show:

Nicola Mometto August 9, 2014 at 4:10 PM

A workaround is now available in tools.analyzer.jvm master, the default behaviour is still to throw on "wrong" tags but it's now available a wrong-tag handler that allows user to customize the behaviour of the validate pass on wrong tags.
PoC: https://github.com/clojure/tools.analyzer.jvm/blob/master/src/test/clojure/clojure/tools/analyzer/jvm/passes_test.clj#L209-L216

Andy Fingerhut April 2, 2014 at 7:24 PM

Ticket TGEN-5 was created on test.generative as a result of this issue, too, with a suggested patch so that test.generative no longer 'leaks' such tag values.

Nicola Mometto December 5, 2013 at 8:00 PM

Nicola Mometto December 5, 2013 at 3:23 PM

This is somewhat an undefined behaviour in clojure, it's not clear to me from the documentation wether tagging elements with things that cannot be resolved to a class should work or not.

I'll ask the clojure-dev ML about this before doing anything.

Thanks

Completed

Details

Assignee

Reporter

Priority

Created December 5, 2013 at 5:28 AM
Updated August 9, 2014 at 4:10 PM
Resolved August 9, 2014 at 4:10 PM