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

fix #36104, assign global name during type definitions #36121

Merged
merged 1 commit into from
Jun 4, 2020

Conversation

JeffBezanson
Copy link
Sponsor Member

Alternative to #36111. Handling re-definitions is the tricky part. I realized one thing we did before was reset the global binding to undefined if an error happens during type definition, but that is invalid, so we don't do it anymore (with or without this PR). Hopefully that is the only remaining difference with v1.4.

This first checks if the new type object might be compatible with an existing one, and if so throws away the new one and uses the old type and parameters. Then we check that each step (supertype and field types) remains compatible as it runs.

fixes #36104

test/core.jl Outdated Show resolved Hide resolved
@JeffBezanson JeffBezanson force-pushed the jb/fix36104-2 branch 2 times, most recently from 5f4fb2a to a2d7011 Compare June 2, 2020 21:57
@JeffBezanson
Copy link
Sponsor Member Author

Well, unsurprisingly, incomplete types throw a wrench into the works. We have some in the tests just to test that case; hopefully it will not really happen outside of that. I think I will return Any from supertype if the supertype is not set, and give an error from fieldtypes?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jun 3, 2020

For soundness, the correct answer for supertype seems would have to be Union{}, not Any. I don't think this PR needs to be changing our handling of supertype, as the current proposal (in #32658) is to not change it.

I think #32658 was adding to the work required to handle incomplete fieldtypes.

@JeffBezanson
Copy link
Sponsor Member Author

I don't think this PR needs to be changing our handling of supertype

But then it breaks callers, like subtypes.

@JeffBezanson
Copy link
Sponsor Member Author

This should be ok now. As a bonus, also fixes #21816!
All it sacrifices is that you can't refer to the new type via its module within the supertype expression, e.g.

struct Foo <: AbstractVector{Mod.Foo}

but I expect that to be extremely rare.

@JeffBezanson JeffBezanson merged commit 095e92d into master Jun 4, 2020
@JeffBezanson JeffBezanson deleted the jb/fix36104-2 branch June 4, 2020 20:27
KristofferC pushed a commit that referenced this pull request Jun 4, 2020
simeonschaub pushed a commit to simeonschaub/julia that referenced this pull request Aug 11, 2020
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.

Referring to Foo.F inside struct F defined in module Foo now errors with UndefVar error
3 participants