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

[SR-14667] Deprecation warning about use of dynamicType when it's a real property #57018

Closed
dabrahams opened this issue May 27, 2021 · 10 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-14667
Radar rdar://problem/78581768
Original Reporter @dabrahams
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, StarterBug
Assignee ehuda (JIRA)
Priority Medium

md5: 3e9f8839ff8ccfb7c26a16ca5bcb2ae4

Issue Description:

struct X {
  let dynamicType = 0
}func f(a: X) -> Bool {
  a.dynamicType == a.dynamicType
}

Yields the warning

x.swift:6:4: error: '.dynamicType' is deprecated. Use 'type(of: ...)' instead
  a.dynamicType == a.dynamicType
   ^~~~~~~~~~~~

which I claim should only come up when no user-defined member name dynamicType exists.

@typesanitizer
Copy link

@swift-ci create

@typesanitizer
Copy link

Would this be a good StarterBug @xedin ?

@xedin
Copy link
Member

xedin commented May 27, 2021

Yeah, I think it would be a good parser starter bug.

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 5, 2021

Comment by Artem Burmistrov (JIRA)

I'd like to work on this, but I have a few questions:

  1. As far as my understanding goes this check should be moved from parser (where it currently is producing error based on parsed token) to semantic analysis. So my question is: where should I start digging?
  2. I kinda thought that the best place to report error could be something related to member lookup. But I struggle to understand lib/sema because it's complicated (especially since I'm a novice). Is that even a correct assumption or the error should be reported somewhere else?

@xedin
Copy link
Member

xedin commented Jun 7, 2021

Terky (JIRA User) Yes, you are correct regarding number one from your list, warning has to be removed from the parser. Type-checker implements "special" `. dynamicType` member as `DynamicTypeOf` constraint in the solver. You'd have to move the warning to constraint solver by adding a new `ConstraintFix` and `FailureDiagnostic` implementations and recording the fix in `ConstraintSystem::simplifyDynamicTypeOfConstraint`. You can take a look at how `AllowCoercionToForceCast` is implemented for example. Let me know if you have any other questions or need help with this.

@swift-ci
Copy link
Collaborator

Comment by Artem Burmistrov (JIRA)

@xedin, thank you for the help. I looked at `DynamicTypeOf` and as far as my understanding goes it is produced from the `type(of: )`, not from the `.dynamicType` member. I also tried to remove error diagnostics from the parser and place the breakpoint in the `ConstraintSystem::simplifyConstraint`. But from what I got there was no `DynamicTypeOf` constraint kind. Is `dynamicType` member even supported as a special member? Also if I remove the `dynamicType` property declaration from the example it would produce the `MissingMemberFailure`. Am I missing something or there should be another place to produce `ConstraintFix`?

@xedin
Copy link
Member

xedin commented Jun 11, 2021

Terky (JIRA User) Once you have removed the diagnostic from the parser, you need to move it to the DiagnosticsSema.def and produce it in `MissingMemberFailure::diagnose` instead of a default missing member diagnostic. Sorry I forgot that `DynamicTypeOf` is only used for `type(of: ...)` since I thought, for some reason, that this was a warning and not an error...

@CodaFi
Copy link
Member

CodaFi commented Aug 26, 2021

It's been 5 years, and `dynamicType` was not exactly a popular feature when it was first introduced. I think we can probably just remove this diagnostic altogether. The chance of confusion stemming from the fallback diagnostic of

value of type 'X' has no member 'dynamicType'

is low. I say we just remove the special case from the parser.

@xedin
Copy link
Member

xedin commented Aug 26, 2021

That sounds good to me!

@swift-ci
Copy link
Collaborator

Comment by Ehud Adler (JIRA)

Merged. PR: #39443

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants