Skip to content
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

Record visited type to prevent stack overflow #788

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Ao-senXiong
Copy link
Member

Fixes #778

@Ao-senXiong Ao-senXiong changed the title Don't recursive when type parameter extends the class itself Don't recurse when type parameter extends the class itself Jul 4, 2024
@Ao-senXiong Ao-senXiong changed the title Don't recurse when type parameter extends the class itself Don't recursively call combine and subsitude if the underlining type is raw Aug 19, 2024
@Ao-senXiong Ao-senXiong changed the title Don't recursively call combine and subsitude if the underlining type is raw Don't recursively call combine and substitute if the underlining type is raw Aug 19, 2024
@Ao-senXiong Ao-senXiong removed their assignment Aug 19, 2024
@Ao-senXiong Ao-senXiong requested a review from wmdietl August 19, 2024 20:34
Copy link
Member

@wmdietl wmdietl left a comment

Choose a reason for hiding this comment

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

As discussed, similar code that uses wildcards instead of raw types still crashes.

@Ao-senXiong Ao-senXiong changed the title Don't recursively call combine and substitute if the underlining type is raw Record visited type to prevent stack overflow Jan 24, 2025
@Ao-senXiong Ao-senXiong requested a review from wmdietl January 24, 2025 12:24
@Ao-senXiong Ao-senXiong assigned wmdietl and unassigned Ao-senXiong Jan 24, 2025
Copy link
Member

@wmdietl wmdietl left a comment

Choose a reason for hiding this comment

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

Thanks!

RawtypeInstantiation<?> wildcardInstance = new @A RawtypeInstantiation<C>();
}

<D extends RawtypeInstantiation<D>> void bar(D b) {
Copy link
Member

Choose a reason for hiding this comment

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

Should the parameter b used for something? Or can it be removed?

// https://github.com/eisop/checker-framework/issues/778
import viewpointtest.quals.*;

public class RawtypeInstantiation<C extends RawtypeInstantiation<C>> {
Copy link
Member

Choose a reason for hiding this comment

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

Can you think of a better class name? The key isn't rawness, it's the C extends R<C> bound, right?


public class RawtypeInstantiation<C extends RawtypeInstantiation<C>> {

void foo() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you pick better names than foo and bar?

RawtypeInstantiation rawtypeInstance = new @A RawtypeInstantiation();
// :: warning: (cast.unsafe.constructor.invocation)
RawtypeInstantiation<D> genericInstance = new @A RawtypeInstantiation<>();
// :: warning: (cast.unsafe.constructor.invocation)
Copy link
Member

Choose a reason for hiding this comment

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

All these warnings distract from the point of this test. Can you add a suitable constructor and suppress the warning there once?

// :: warning: (cast.unsafe.constructor.invocation)
RawtypeInstantiation<D> genericInstance = new @A RawtypeInstantiation<>();
// :: warning: (cast.unsafe.constructor.invocation)
RawtypeInstantiation<?> wildcardInstance = new @A RawtypeInstantiation<D>();
Copy link
Member

Choose a reason for hiding this comment

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

How do these tests ensure the proper viewpoint adaptation happened?

if (visitedTypes.contains(declared)) {
return declared;
}
try {
Copy link
Member

Choose a reason for hiding this comment

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

Are there really exceptions that can happen in this code? Adding these large try blocks makes it hard to see what changed.

@wmdietl wmdietl assigned Ao-senXiong and unassigned wmdietl Feb 24, 2025
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.

Stack overflow in combineAnnotationWithType when check generics extends itself to list
2 participants