Skip to content

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Mar 4, 2025

Extend "encoded package name" warning to file package object names.

Original ticket for warning is #14448

Fixes #22670

Doesn't yet address Cyclic macro dependencies.

Also packageObjectName is "forced" early to avoid cycles, even if there is no top-level def.

Also we write foo-bar.scala for descriptive snippets with top-level defs. Unreasonable to warn about that.

@som-snytt
Copy link
Contributor Author

Practicing closing PRs for reworking instead of leaving them as drafts.

@som-snytt som-snytt closed this Mar 6, 2025
@som-snytt som-snytt reopened this Aug 17, 2025
@som-snytt
Copy link
Contributor Author

Related issue #22866 was scaladoc receiving names via tasty, where the package prefix and class name must be encoded (apparently because scaladoc would split on dot?). I don't remember the details, but it sounds ad hoc and perhaps wrong.

The scaladoc issue was the filename a.b.scala with name a.b and suffix .scala. (The use case was a.test.scala.) Then the package object uses a.b; the original ticket for the warning says tasty supplies an encoded package name, but compiler unencoded. Then maybe the warning for package object a.b or a-b should be guided by whether there is a corresponding package (under either name), in order to avoid warning about snippets.

A package

a.`b.c`.d

must preserve segments; the name is a.b$dotc.d.

If that isn't handled uniformly (correctly), then warning is the best effort.

@som-snytt
Copy link
Contributor Author

status quo for hyphen in package name but not in file package object name:

-- Warning: /tmp/macro.scala:2:8 -----------------------------------------------
2 |package `X-Y` // explicit package name gets a diagnostic
  |        ^^^^^
  |The package name `X-Y` will be encoded on the classpath, and can lead to undefined behaviour.
1 warning found
-- Error: /tmp/usage.scala:4:8 -------------------------------------------------
4 |val x = foo // warn
  |        ^^^
  |Failed to evaluate macro.
  |  Caused by class java.lang.ClassNotFoundException: X-Y.macro$package$

So it's sufficient to add the warning for file package object name. It's desirable not to warn for snippets.

@som-snytt som-snytt force-pushed the issue/22670-hyphenated-package branch from 426e828 to f916723 Compare August 17, 2025 23:43
@som-snytt som-snytt force-pushed the issue/22670-hyphenated-package branch from f916723 to 425ad15 Compare August 18, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cyclic macro dependencies "caused" by a dash (-) in the filename?

1 participant