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

Support derived to base conversions. #3487

Merged
merged 6 commits into from
Dec 11, 2023

Conversation

zygoloid
Copy link
Contributor

@zygoloid zygoloid commented Dec 9, 2023

This is enough to support calling methods that take a Base or Base* as their self. But name lookup doesn't look in the base class yet, so base class methods aren't actually found.

@zygoloid zygoloid changed the title Support derived to base pointer conversions. Support derived to base conversions. Dec 9, 2023
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

Looks good.

fn ConvertInit() {
let a: A = {.base = {.base = {.a = 1}, .b = 2}, .c = 3} as C;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the code works for it, but should there be some tests of non-class-type bases? e.g.:

Suggested change
class StructBase {
extend base: {.x: i32};
}
fn ConvertStructBaseValue(v: StructBase) {
let s: {.x: i32} = v;
}
fn ConvertStructBase(p: StructBase*) -> {.x: i32}* { return p; }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Added to fail_base_bad_type.carbon because we don't allow such inheritance at all at the moment, but it seems good to make sure that it at least doesn't crash.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, for some reason I was thinking it was allowed.

@zygoloid zygoloid added this pull request to the merge queue Dec 11, 2023
Merged via the queue into carbon-language:trunk with commit 87d341c Dec 11, 2023
6 checks passed
@zygoloid zygoloid deleted the toolchain-base-convert branch December 11, 2023 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants