8000 fix: deep virtual package by peter-jerry-ye · Pull Request #829 · moonbitlang/moon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: deep virtual package #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2025
Merged

Conversation

peter-jerry-ye
Copy link
Contributor

Related Issues

  • Related issues: #____

When handling the deep nested virtual package, the relative path is misused.

Type of Pull Request

  • Bug fix
  • New feature
    • I have already discussed this feature with the maintainers.
  • Refactor
  • Performance optimization
  • Documentation
  • Other (please describe):

Does this PR change existing behavior?

  • [] Yes (please describe the changes below)

  • No

Does this PR introduce new dependencies?

  • No
  • Yes (please check binary size changes)

Checklist:

  • Tests added/updated for bug fixes or new features
  • Compatible with Windows/Linux/macOS

Copy link
Potential file name extraction issue in virtual MBTI file path construction

Category
Correctness
Code Snippet
rel.file_name().map(|x| x.to_string_lossy()).unwrap_or_else(|| mod_desc.name.rsplit('/').next().expect('Empty module name').into())
Recommendation
Add validation for mod_desc.name before using rsplit and explicit error handling:

if mod_desc.name.is_empty() {
    anyhow::bail!("Module name cannot be empty");
}
rel.file_name()
    .map(|x| x.to_string_lossy())
    .unwrap_or_else(|| {
        mod_desc.name
            .rsplit('/')
            .next()
            .ok_or_else(|| anyhow::anyhow!("Invalid module name format"))?            
            .into()
    })

Reasoning
The current implementation assumes mod_desc.name will always contain at least one '/' character and won't be empty. This could lead to panics if these assumptions are violated. Better error handling would make the code more robust.

Missing inline documentation for virtual package handling logic

Category
Maintainability
Code Snippet
virtual_mbti_file: if pkg.virtual_pkg.is_some() {
let virtual_mbti_file = pkg_path.join(format!(...));
...
}
Recommendation
Add documentation explaining the virtual package path construction logic:

// Constructs the path to the virtual MBTI file by either:
// 1. Using the relative path's filename if available
// 2. Falling back to the last component of the module name
virtual_mbti_file: if pkg.virtual_pkg.is_some() {

Reasoning
The virtual package path construction logic is complex and the reasoning behind the fallback mechanism isn't immediately clear. Documentation would help future maintainers understand the code's purpose.

Consistent package naming convention in test files

Category
Maintainability
Code Snippet
package "username/hello/deep/lib"
...
package "username/hello"
Recommendation
Consider using a more descriptive or standardized naming pattern for test packages, such as:

package "test/virtual/deep/lib"
...
package "test/virtual"
**Reasoning**
Using 'username' as a package prefix in test files might be confusing. A more explicit naming convention would make it clearer that these are test packages and how they relate to each other in the hierarchy.

</details>

Comment on lines +567 to +569
.rsplit('/')
.next()
.expect("Empty module name")
Copy link
Collaborator
@lynzrand lynzrand May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: This is obviously not the most elegant way to do the task, but is there any existing aux functions that does the task?

@lynzrand lynzrand requested a review from Young-Flash May 27, 2025 03:45
@peter-jerry-ye peter-jerry-ye enabled auto-merge (rebase) May 28, 2025 02:46
@peter-jerry-ye peter-jerry-ye merged commit eacf15c into main May 28, 2025
23 of 25 checks passed
@peter-jerry-ye peter-jerry-ye deleted the zihang/fix-deep-virtual-package branch May 28, 2025 03:05
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.

3 participants
0