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

Fuzzer issue: extending a member class as a base class #2994

Closed
josh11b opened this issue Jul 18, 2023 · 0 comments · Fixed by #2995
Closed

Fuzzer issue: extending a member class as a base class #2994

josh11b opened this issue Jul 18, 2023 · 0 comments · Fixed by #2995
Labels
explorer Action items related to Carbon explorer code

Comments

@josh11b
Copy link
Contributor

josh11b commented Jul 18, 2023

Description of the bug:

Proposal #2760 moved the declaration of a base class from the class declaration line into the body of the class definition. This change was implemented in Explorer in #2906 . However, this change did not account for the consequence of this change that the base class expression could now refer to something declared earlier in class scope. The implementation in #2906 of TypeChecker::DeclareClassDeclaration(...) in explorer/interpreter/type_checker.cpp type checks the base class expression before DeclareDeclaration(...) can be called on the members. If the base class expression contains a reference to a member (such as a member class), it fails when it tries to access that member's static_type, which hasn't been set yet.

Unfortunately, this code is difficult to reorder, since the members can refer to Self which is a NominalClassType created in this function, with base_class as a parameter, which we don't know until we've processed the extend base declaration.

What did you do, or what's a simple way to reproduce the bug?

This triggers the bug:

package P impl;

class C {
  class D { }
  extend base: D;
}

fn Main() -> i32 { return 0; }

This does not:

package P impl;

class D { }
class C {
  extend base: D;
}

fn Main() -> i32 { return 0; }

What did you expect to happen?

No crash. This code should instead produce some compilation error about trying to extend a class that is final.

What actually happened?

Crash:

... optional:943: _LIBCPP_ASSERT 'this->has_value()' failed. optional operator* called on a disengaged value

Any other information, logs, or outputs that you want to share?

No response

@josh11b josh11b added the explorer Action items related to Carbon explorer code label Jul 18, 2023
github-merge-queue bot pushed a commit that referenced this issue Jul 24, 2023
chandlerc pushed a commit to chandlerc/carbon-lang that referenced this issue Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
explorer Action items related to Carbon explorer code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant