GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix: Raise SemanticError for unsupported inline class instantiation #2826 by amritamishra01 · Pull Request #2873 · lcompilers/lpython

Conversation

@amritamishra01

@amritamishra01 amritamishra01 commented Dec 8, 2025

Copy link
Copy Markdown

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:

  1. 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.
  2. 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@amritamishra01
Fix: Raise SemanticError for unsupported inline class instantiation l…
fd3fbcc
…compilers#2826
@swamishiju

swamishiju commented Dec 8, 2025

Copy link
Copy Markdown
Collaborator

Hello, @amritamishra01 the MacOS CI is currently broken it needs to be fixed. A lot of work is currently being focused on the back end over at the LFortran repo. I suggest you contact @certik on zulip.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@swamishiju

swamishiju commented Dec 8, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

#2875 Should fix it, its a small change so I merged it. In regards to the other PRs you have up you can ask on zulip.

You can rebase your branches on top of main to get the CIs working

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@amritamishra01
Merge branch 'main' into fix/inline-loop-bug
aba1f60
@amritamishra01

amritamishra01 commented Dec 11, 2025

Copy link
Copy Markdown
Author

Update: Rebased on the latest main and all CI checks are now passing (18/18).

I have verified the fix locally and confirmed the tests pass on the CI. This is ready for final review!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Inplace class definitions causes infinite looping

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@amritamishra01 @swamishiju
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.