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-10766] Incorrect error message: "Double is not convertible to Decimal" #53156

Open
swift-ci opened this issue May 24, 2019 · 3 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10766
Radar None
Original Reporter JaydenIrwin (JIRA User)
Type Bug
Environment

Xcode Version 10.2.1 (10E1001)

macOS 10.14.5 (18F132)

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

md5: 34f813ad0acc719bbde11fc25e43bbb3

Issue Description:

In the following code, the correct error should be that the 1st product in the array is missing a description. The error code given by Xcode is that for the 2nd product, 9.99 is "Double is not convertible to Decimal". Removing the 1st product, fixes the error on the 2nd product.

Data models:

class Product: Codable {
init(name: String, imageNames: [String], shortDescription: String, description: String, urlSuffix: String, option1: String = "nil", option2: String = "nil", option3: String = "nil", variants: [Variant]) { ... }
...
}
class Variant: Codable {
init(id: Int, sku: String, option1: String = "nil", option2: String = "nil", option3: String = "nil", boxPieceCount: Int, price: Decimal) { ... }
...
}

Code:

products = [
Product(name: "...", imageNames: ["..."], shortDescription: "...", urlSuffix: "", option1: "...", variants: [
        Variant(id: 123, sku: "...", option1: "...", boxPieceCount: 1, price: 4.99)
        ]),
    Product(name: "...", imageNames: ["..."], shortDescription: "...", description: "...", urlSuffix: "", option1: "...", variants: [
        Variant(id: 123, sku: "...", option1: "...", boxPieceCount: 1, price: 9.99)
        ]),
...
]
@belkadan
Copy link
Contributor

cc @xedin

@swift-ci
Copy link
Collaborator Author

Comment by Martin Pilkington (JIRA)

I've also just encountered this bug. In my case it was misspelling a method on NSLayoutAnchor

import Cocoa

let view1 = NSView()
let view2 = NSView()

//This only happens inside an array
let constraints = [
    view1.leadingAnchor.constraint(equalTo: view2.leadingAnchor, constat: 10), //Actual error is the missing 'n' here
    view1.trailingAnchor.constraint(equalTo: view2.trailingAnchor, constant: 10) //Error "'Int' is not convertable to 'CGFloat'" appears here
]

I tried to reproduce this using some simple classes but it doesn't seem to fail, so it doesn't seem to be the case that if fails every time you have a misspelled method inside an array. Hopefully another test case helps fix the issue

@theblixguy
Copy link
Collaborator

Have you tried a 5.2 development snapshot? This is what I get:

/Users/suyashsrijan/Desktop/test.swift:7:33: error: incorrect argument label in call (have 'equalTo:constat:', expected 'equalTo:constant:')
  view1.leadingAnchor.constraint(equalTo: view2.leadingAnchor, constat: 10),
                                ^                              ~~~~~~~
                                                               constant

So I think this is fixed.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants