Title: Fix: Raise SemanticError for unsupported inline class instantiation #2826 by amritamishra01 · Pull Request #2873 · lcompilers/lpython · GitHub
Open Graph Title: Fix: Raise SemanticError for unsupported inline class instantiation #2826 by amritamishra01 · Pull Request #2873 · lcompilers/lpython
X Title: Fix: Raise SemanticError for unsupported inline class instantiation #2826 by amritamishra01 · Pull Request #2873 · lcompilers/lpython
Description: Summary Hi @swamishiju Fixes #2826 where the compiler hangs (infinite loop) when encountering inline class instantiation, such as print(Foo(10)). The Issue Currently, the compiler attempts to lower temporary class objects created inline but fails to handle the lifecycle correctly in python_ast_to_asr.cpp, resulting in infinite recursion/hanging during the lowering phase. The Fix I implemented a check in the semantic analysis phase (visit_Call) to detect this unsupported pattern before it reaches the lowering stage. File: src/lpython/semantics/python_ast_to_asr.cpp Logic: The visitor now checks if a function call argument is a direct Call to a Struct (Class) symbol. Action: If detected, it raises a clear SemanticError advising the user to assign the object to a variable first. Verification I added two new test cases to ensure the fix works and is safe: Error Case: tests/errors/test_inline_class_error.py Contains print(Foo(10)) and my_func(Foo(20)). Verified that it now raises a SemanticError immediately instead of hanging. Regression Test: tests/reference/pass_inline_class_safe.py Contains a = Foo(10); print(a). Verified that valid usage (assigning to a variable first) still compiles and produces correct ASR. Future Work This is a safeguard fix. Full support for inline class instantiation will require implementing proper lowering logic for temporary class objects, likely by separating symbol registration from body lowering to handle recursive resolution.
Open Graph Description: Summary Hi @swamishiju Fixes #2826 where the compiler hangs (infinite loop) when encountering inline class instantiation, such as print(Foo(10)). The Issue Currently, the compiler attempts to lowe...
X Description: Summary Hi @swamishiju Fixes #2826 where the compiler hangs (infinite loop) when encountering inline class instantiation, such as print(Foo(10)). The Issue Currently, the compiler attempts to lowe...
Opengraph URL: https://github.com/lcompilers/lpython/pull/2873
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:89b47700-8508-51a0-46ce-4595367298e0 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A6D4:2C62EA:30C2474:439A36F:6977C1F8 |
| html-safe-nonce | 4241ac9538badaa204eb6985d91cb535629cb0c3da4705453173e230f04f8116 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNkQ0OjJDNjJFQTozMEMyNDc0OjQzOUEzNkY6Njk3N0MxRjgiLCJ2aXNpdG9yX2lkIjoiMjk1ODAzODA1OTc4MzI3NTAwMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3a23c370a16536b6e374bd6b38a22c70f16be4e48a7a149362441515efeb59f5 |
| hovercard-subject-tag | pull_request:3080801794 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/lcompilers/lpython/pull/2873/files |
| twitter:image | https://avatars.githubusercontent.com/u/171616930?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/171616930?s=400&v=4 |
| og:image:alt | Summary Hi @swamishiju Fixes #2826 where the compiler hangs (infinite loop) when encountering inline class instantiation, such as print(Foo(10)). The Issue Currently, the compiler attempts to lowe... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | dd7783bd9901db88bac6bc215af7f020bc205a04ebc67e6c7def882ef2859ecd |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/lcompilers/lpython git https://github.com/lcompilers/lpython.git |
| octolytics-dimension-user_id | 96538276 |
| octolytics-dimension-user_login | lcompilers |
| octolytics-dimension-repository_id | 442864346 |
| octolytics-dimension-repository_nwo | lcompilers/lpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 442864346 |
| octolytics-dimension-repository_network_root_nwo | lcompilers/lpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5d30081a77a5d66860584073cb38fd98fd7f9388 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width