Skip to content

Allow targetName for object package #24217

@som-snytt

Description

@som-snytt

Compiler version

3.7.3

Minimized code

  cat something-else.scala

import annotation.*

package p:
  package q:
    @targetName("mypq")
    object `package`:
      private[p] def f = 42

Output

  scala-cli compile --server=false -S 3.7.3 something-else.scala
-- [E169] Syntax Error: /home/amarki/snips/something-else.scala:7:12 -----------
7 |    object `package`:
  |            ^
  |          @targetName annotation not allowed on top-level package object q
  |
  | longer explanation available when compiling with `-explain`
1 error found
Compilation failed

Expectation

Since the file name, and therefore the package object name, is arbitrary and may require special encoding, I would like to "fix" the name to something benign (instead of something-else).

Packages don't take annotations, but object syntax does, and possibly package object syntax could be made to.

It would be nice if targetName were permitted for package objects.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions