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

Sema: Do not drop reference to type paramater if it reduces to ErrorType #79065

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AnthonyLatsis
Copy link
Collaborator

Resolves #77840.

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@slavapestov
Copy link
Contributor

Given the original bug report:

Unhandled coercion:
(dependent_member_type assoc_type="test.(file).P.A@/Users/anthonylatsis/Desktop/test.swift:381:18"
  (base=existential_type
    (protocol_type decl="test.(file).P@/Users/anthonylatsis/Desktop/test.swift:380:10")))
(dependent_member_type assoc_type="test.(file).P.A@/Users/anthonylatsis/Desktop/test.swift:381:18"
  (base=opened_archetype_type address=0x14e170000 conforms_to="test.(file).P@/Users/anthonylatsis/Desktop/test.swift:380:10" opened_existential_id="F8EFB1A8-ABED-11EF-AA89-2E7849F3693B"
    (interface_type=generic_type_param_type depth=0 index=0 param_kind=type)
    (opened_existential=existential_type
      (protocol_type decl="test.(file).P@/Users/anthonylatsis/Desktop/test.swift:380:10"))))

I think the actual bug here is that we end up in CSApply even when the code was invalid. We should never have a DependentMemberType with a concrete base type like that.

struct G<T> {}

protocol P {
associatedtype A where A == Undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the behavior here any different than the case where Undefined exists?

Copy link
Collaborator Author

@AnthonyLatsis AnthonyLatsis Jan 30, 2025

Choose a reason for hiding this comment

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

The way I think about it is that if reduction returns an error type, then it makes sense to ignore the constraint that caused it to error out. That is, to not treat that error type as concrete when searching for type parameter references.

@AnthonyLatsis
Copy link
Collaborator Author

I think the actual bug here is that we end up in CSApply even when the code was invalid. We should never have a DependentMemberType with a concrete base type like that.

I will have a look at what the erasure algorithm is doing.

@AnthonyLatsis
Copy link
Collaborator Author

This is why we end up with up with an archetype base:

auto result = conformance.getTypeWitness(lookupBaseType, assocType);
if (result && !result->hasError())
return result;
}
return DependentMemberType::get(lookupBaseType, assocType);

@slavapestov
Copy link
Contributor

Perhaps we shouldn’t proceed to CSApply if there are type variables with fixed types that contain dependent member types? We can treat them like free type variables perhaps.

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.

Crash on illegal existential method reference containing undefined type in signature
2 participants