Skip to content

Prevent .foo and .-foo symbols from being used outside call position #691

@jeaye

Description

@jeaye

Clojure doesn't allow either of these:

❯ clj
Clojure 1.12.4
user=> (let [.-foo 3] (println .-foo))
Syntax error (ClassFormatError) compiling fn* at (REPL:1:1).
Illegal field name "._foo" in class user$eval134

user=> (let [.foo 3] (println .foo))
Syntax error (ClassFormatError) compiling fn* at (REPL:1:1).
Illegal field name ".foo" in class user$eval136

We should do the same. Right now, we allow them during analysis and then fail during codegen, since we're not expecting . in any symbols and we don't munge that character. We shouldn't need to fix the munging if we prevent this during analysis anyway. These member symbols can only be used in call position.

Looks like we do this in some cases, but not others.

user=> (println .-foo)
─ analyze/invalid-cpp-position ─────────────────────────────────────────────────────────────────────
error: Unable to use this form as a value. It needs to be called directly. For example, `(.-foo
       ...)`.
─────┬──────────────────────────────────────────────────────────────────────────────────────────────
     │ /tmp/nix-shell.uXQXWk/nix-shell-624665-2256689764/jank-repl-UtZnuG
─────┼──────────────────────────────────────────────────────────────────────────────────────────────
  1  │ (println .-foo)
     │          ^^^^^ Found here.
─────┴──────────────────────────────────────────────────────────────────────────────────────────────

user=> (let [.-foo 3] )
In file included from <<< inputs >>>:1:
input_line_346:5:111: error: cannot use dot operator on a type
    5 | jank::runtime::object_ref call() const final {jank::runtime::oref<jank::runtime::object> let_11{ }; {{ auto &&._foo_9(const_12); return jank::r...
      |                                                                                                               ^
error: Parsing failed.
─ internal/codegen-failure ─────────────────────────────────────────────────────────────────────────
error: Unable to compile C++ source.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions