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-5594] Unexpected error: Cannot call value of non-function type 'Data?' #48166

Closed
swift-ci opened this issue Jul 31, 2017 · 6 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5594
Radar rdar://problem/33655132
Original Reporter BenLeggiero (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode Version 9.0 beta 3 (9M174d)
macOS 10.12.6 (16G29)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee @xedin
Priority Medium

md5: 0890e579e92a51e271134ebf2834f1af

relates to:

  • SR-456 Confusing build error when calling 'max' function within 'extension Int'

Issue Description:

Observed Behavior:

In the following example adapted from the Special Picture Protocol sample code:

import Cocoa

/* NSImage -> jfif utility category. */

extension NSImage { // (JFIFConversionUtils)

    /* returns jpeg file interchange format encoded data for an NSImage regardless of the
     original NSImage encoding format.  compressionValue is between 0 and 1.
     values 0.6 thru 0.7 are fine for most purposes.  */
    func jfifData(compressionValue: CGFloat) -> Data? {

        /* convert the NSImage into a raster representation. */
        guard
            let tiffData = self.tiffRepresentation(using: .jpeg, factor: compressionValue),
            let myBitmapImageRep = NSBitmapImageRep(data: tiffData)
            else {
                assertionFailure("Could not generate TIFF representation")
                return nil
        }


        /* convert the bitmap raster representation into a jfif data stream and return the jfif encoded data */
        return myBitmapImageRep.representation(using: .jpeg, properties: [.compressionFactor : NSNumber(value: compressionValue)])
    }
}

This compile-time error is emitted:

/path/to/source.swift:24:51: error: cannot call value of non-function type 'Data?'
            let tiffData = self.tiffRepresentation(using: .jpeg, factor: compressionValue),
                           ~~~~~~~~~~~~~~~~~~~~~~~^

Expected behavior:

An error like this is emitted:

/path/to/source.swift:24:90: error: cannot convert value of type 'CGFloat' to expected argument type 'Float'
            let tiffData = self.tiffRepresentation(using: .jpeg, factor: compressionValue),
                                                                         ^~~~~~~~~~~~~~~~
@swift-ci
Copy link
Collaborator Author

Comment by Ky (JIRA)

Appears to be similar in symptoms to SR-456

@belkadan
Copy link
Contributor

belkadan commented Aug 1, 2017

It's a little different because SR-456 is about being unable to use a top-level function, whereas in this case we have a method with the same base name as a property.

cc @xedin

@belkadan
Copy link
Contributor

belkadan commented Aug 1, 2017

@swift-ci create

@xedin
Copy link
Member

xedin commented Aug 1, 2017

BenLeggiero (JIRA User) I've recently made improvements in this area, and it looks like on master it produces expected diagnostic:

error: cannot convert value of type 'CGFloat' to expected argument type 'Float'
              let tiffData = self.tiffRepresentation(using: .jpeg, factor: compressionValue),
                                                                           ^~~~~~~~~~~~~~~~
                                                                           Float(          )

Can you please verify with the latest nightly build?

@swift-ci
Copy link
Collaborator Author

Comment by Ky (JIRA)

@xedin, I'm not sure how to do that. In what Xcode build is it expected? I can get back to you then 🙂

@xedin
Copy link
Member

xedin commented Aug 13, 2017

BenLeggiero (JIRA User) We can't give any guarantees regarding to which Xcode build these changes are going to end up in, but what you could do is to download the latest nightly build from swift.org and try your example to see if it behaves correctly...

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants