Skip to content

--report-glean fix: Name methods on Literal and LiteralString receivers by their class - #5605

Closed
Quaden2307 wants to merge 3 commits into
meta:mainfrom
Quaden2307:fix-glean-literal-class
Closed

Quaden2307 wants to merge 3 commits into
meta:mainfrom
Quaden2307:fix-glean-literal-class

Conversation

@Quaden2307

Copy link
Copy Markdown
Contributor

Summary

--report-glean would not properly name a method on a Literal or LiteralString receiver. For example, "hello".title() would emit title rather than the expected str.title. This is because the closure that finds a method's defining class only handled class types, so a Literal fell through without a class name. The fix was at the start of defining_type closure, a Type::Literal is converted to its class with general_class_type, and a Type::LiteralString to str. The existing ClassType arm after that handles the naming.

Fixes #5250

  • I am a human, and I fully understand the code I am submitting.

Test Plan

Added a string_literal case to the glean snapshot_test, with the five receivers from the issue. The snapshot was regenerated and all five methods now show as str.title/str.join. cargo test snapshot_test passes, and none of the other snapshots changed. test.py lint also passes.

@github-actions

Copy link
Copy Markdown

✅ This PR meets all requirements from our pull request checklist.

Optional recommendations:

  • This PR is very large, which makes it slow and difficult to review. We strongly recommend splitting it into smaller PRs that can be merged independently. If that isn't possible, please structure it as a series of small commits. If you've already split it as far as is practical, no action is needed.

Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour.

@meta-codesync

meta-codesync Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D131090557. (Because this pull request was imported automatically, there will not be any future comments.)

@rchen152 rchen152 self-assigned this Nov 11, 2026

@rchen152 rchen152 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR! I left one readability suggestion. Once that's addressed, this should be good to merge.

Comment thread pyrefly/lib/report/glean/convert.rs Outdated
let defining_type = |ty: Type| {
// A literal is an instance of its general class (e.g. `"a"` is a `str`),
// so its members are named after that class.
let ty = match ty {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Splitting the logic between two matchs makes it sort of hard to read. I'd recommend something like:

let cls = match &ty {
    ...  // extract the `ClassType`
    _ => return ty,
};
// get the class member, falling back to `Type::ClassType(cls.clone())`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks for the feedback!

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@rchen152 rchen152 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@rchen152

Copy link
Copy Markdown
Contributor

Thanks again, @Quaden2307!

@meta-codesync

meta-codesync Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 5619b5e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--report-glean names a method on a Literal or LiteralString receiver without its class (title, not str.title)

2 participants