fmease / lushui

The reference compiler of the Lushui programming language
Apache License 2.0
5 stars 0 forks source link

Legal transitive `use`s of (illegal) re-exports of more private bindings reported #101

Open fmease opened 2 years ago

fmease commented 2 years ago

Example to reproduce:

use space.thing
module space of
    @public use Thing as thing
    data Thing: Type of

(Relevant) stderr:

error[E009]: re-export of the more private binding `topmost.space.Thing`
 --> a.lushui:1:11
  |
1 | use space.thing
  |           ^^^^^ re-exporting binding with greater exposure
  |
 --> a.lushui:4:10
  |
4 |     data Thing: Type of
  |          ----- re-exported binding with lower exposure
  |
 note: expected the exposure of `topmost.thing`
                  to be at most `topmost.space`
             but it actually is `topmost`

error[E009]: re-export of the more private binding `topmost.space.Thing`
 --> a.lushui:3:26
  |
3 |     @public use Thing as thing
  |                          ^^^^^ re-exporting binding with greater exposure
  |
 --> a.lushui:4:10
  |
4 |     data Thing: Type of
  |          ----- re-exported binding with lower exposure
  |
 note: expected the exposure of `topmost.space.thing`
                  to be at most `topmost.space`
             but it actually is unrestricted

Ideally, it should only report:

error[E009]: re-export of the more private binding `topmost.space.Thing`
 --> a.lushui:3:26
  |
3 |     @public use Thing as thing
  |                          ^^^^^ re-exporting binding with greater exposure
  |
 --> a.lushui:4:10
  |
4 |     data Thing: Type of
  |          ----- re-exported binding with lower exposure
  |
 note: expected the exposure of `topmost.space.thing`
                  to be at most `topmost.space`
             but it actually is unrestricted

The cause of the bug is collapse_use_chain which loses the information of whether a binding is a direct or a transitive use. If we remove the collapsing logic in collapse_use_chain (but keeping the UnresolvedUseBinding logic), the bug goes away. However, everything else breaks like the check if something is a namespace or not which assumes collapsed uses (obviously; as designed).

fmease commented 2 years ago

Just add a flag Direct vs. Transitive to EntityKind::Use??