Tensegritics / Tensegritics/ClojureDart

Compiler bug: `rename-lib` injects bogus imports when compiling test namespaces

Open
#380 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
1.6k
Forks
119
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

When a ClojureDart namespace is compiled as a test namespace, the compiler renames its output path from lib/cljd-out/... to test/cljd-out/.... The rename-lib helper then updates every namespace's :imports map, but it unconditionally adds the renamed library even to namespaces that never imported the original library. This produces invalid import statements in generated Dart files, which break both flutter test and dart analyze for any project that mixes .cljd tests with hand-written Dart widget tests.

Does your problem persist after clj -M:cljd clean && flutter clean?

No, but that's kinda the point. I don't think I should have to run clean commands between between running clj tests and and flutter tests.

Reproduction

Environment:

  • ClojureDart SHA: 81b5c03a55cf52b21dc0be8ccfa4827b9889f488
  • Project kind: :flutter
  • Command: clj -M:test:cljd test

Steps to reproduce:

  1. Create a minimal Flutter/ClojureDart project.
  2. Add a .cljd test namespace under test/ using cljd.test.
  3. Add a hand-written Dart widget test that imports package:<name>/main.dart.
  4. Run clj -M:test:cljd test without restricting the test path.

Behavior

Expected:

Both the ClojureDart test and the Flutter widget test should load and run, without needing to clean generated files in between.

Actual:

flutter test fails to load the widget test with errors like:

lib/cljd-out/cljd/core.dart:7:8: Error: Error when reading 'lib/test/cljd-out/repro/core-test_test.dart': No such file or directory
import "../../../test/cljd-out/repro/core-test_test.dart" as lcorc_test;
       ^

The relative import inside lib/cljd-out/... resolves through the package root to lib/test/..., which does not exist.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the rename-lib helper in the compiler and trace how it rewrites :imports when a test namespace moves from lib/cljd-out to test/cljd-out. Reproduce with clj -M:test:cljd test in a Flutter project, then verify that generated Dart imports only reference libraries actually imported and that both flutter test and dart analyze work without cleaning.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
compilers, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.