Skip to content

[Sema] Propagate invalid bit during default param checking #28106

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

Closed
wants to merge 1 commit into from

Conversation

davezarzycki
Copy link
Contributor

@davezarzycki
Copy link
Contributor Author

@swift-ci please smoke check

@CodaFi
Copy link
Contributor

CodaFi commented Nov 6, 2019

Sure, this is one way to do it. I think teaching default argument checking to be more careful with invalid parameters is another. What do you think @hamishknight?

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Unfortunately, I don't believe this will fix multi-file cases given we only check default arguments as a part of the parameter list for primary files. For example:

// a.swift
func foo(_ x: String = #line) {}

// b.swift
foo()

If we compile b.swift as a primary file, we'll still hit the assertion in CSApply as we haven't otherwise type-checked the default param.

My plan for fixing this was to move the caller-side default type-checking logic out of CSApply and into a request that can be called from SILGen when it wants to lower the default arg. That way we can still produce a complete solution for the apply even if the default arg is invalid (and we don't want to involve the default arg checking as a part of solving, as we don't want it to affect the solution's score). I'm waiting for #27756 to land first though.

@xedin
Copy link
Contributor

xedin commented Nov 6, 2019

@theblixguy had a PR which checked default arguments as part of the constraint system and could produce a nice tailored diagnostic for it, unfortunately in come cases that argument conversion relation should adjust the score so we had to revert it, but I think it's possible to avoid that behavior - #26973

I still think it makes sense as part of the solver, because we shouldn't be producing invalid solutions.

@hamishknight
Copy link
Contributor

@xedin I was planning on using DefaultArgumentExpr to represent both caller-side and callee-side defaults, which would allow us to produce a valid solution for an invalid caller-side default (which is currently what we already do for callee defaults). IMO the constraint system shouldn't care about the difference between these defaults, that's something SILGen should take care of.

As a nice bonus, this will also allow us to remove CallerDefaultArgumentExpr :)

@xedin
Copy link
Contributor

xedin commented Nov 6, 2019

I'll be happy with anything with doesn't require a call to typeCheckExpression in CSApply and produces good diagnostics :)

@davezarzycki
Copy link
Contributor Author

Looks like people have better ideas. Closing.

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.

4 participants