-
-
Notifications
You must be signed in to change notification settings - Fork 163
fix: call getters inherited through dynamic class heritage #11012
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
Closed
+96
−0
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Fixed | ||
|
|
||
| - Direct calls through static getters inherited from a factory-produced class now invoke the getter's returned function, including on further subclasses. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //! Direct calls through class getters invoke the value returned by the getter. | ||
|
|
||
| use std::path::PathBuf; | ||
| use std::process::Command; | ||
|
|
||
| #[test] | ||
| fn direct_calls_through_instance_and_static_getters() { | ||
| let dir = tempfile::tempdir().expect("tempdir"); | ||
| let entry = dir.path().join("main.ts"); | ||
| let binary = dir.path().join("main_bin"); | ||
| std::fs::write( | ||
| &entry, | ||
| r#" | ||
| let reads = 0; | ||
| class C { | ||
| get g() { reads++; return (n: number) => n + 2; } | ||
| } | ||
| const c = new C(); | ||
| console.log("instance", c.g(1), reads); | ||
| const instanceFn = c.g; | ||
| console.log("read then call", instanceFn(1), reads); | ||
|
|
||
| function make() { | ||
| const cache = new Map<any, any>(); | ||
| return class { | ||
| static get g() { | ||
| if (!cache.has(this)) cache.set(this, (n: number) => n + 8); | ||
| return cache.get(this); | ||
| } | ||
| }; | ||
| } | ||
| class G extends make() {} | ||
| class H extends G {} | ||
| const staticFn = G.g; | ||
| console.log("static read", staticFn(1)); | ||
| console.log("static direct", G.g(1), H.g(2)); | ||
| "#, | ||
| ) | ||
| .expect("write fixture"); | ||
|
|
||
| let compile = Command::new(PathBuf::from(env!("CARGO_BIN_EXE_perry"))) | ||
| .current_dir(dir.path()) | ||
| .arg("compile") | ||
| .arg(&entry) | ||
| .arg("-o") | ||
| .arg(&binary) | ||
| .arg("--no-cache") | ||
| .output() | ||
| .expect("compile fixture"); | ||
| assert!( | ||
| compile.status.success(), | ||
| "compile failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&compile.stdout), | ||
| String::from_utf8_lossy(&compile.stderr) | ||
| ); | ||
|
|
||
| let run = Command::new(binary) | ||
| .current_dir(dir.path()) | ||
| .output() | ||
| .expect("run fixture"); | ||
| assert!( | ||
| run.status.success(), | ||
| "fixture failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&run.stdout), | ||
| String::from_utf8_lossy(&run.stderr) | ||
| ); | ||
| assert_eq!( | ||
| String::from_utf8_lossy(&run.stdout), | ||
| "instance 3 1\nread then call 3 2\nstatic read 9\nstatic direct 9 10\n" | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Remove the fixed inheritance-depth limit.
A runtime-resolved parent at depth 64 or greater does not set
has_dynamic_parent. The call then uses the previous static-method path, so a callable inherited static getter still fails for valid deep class hierarchies. Walk untilextends_nameis absent, as the static method and field resolution loops above do.🤖 Prompt for AI Agents