swift icon indicating copy to clipboard operation
swift copied to clipboard

[SR-294] Strange errors for unary prefix operator with tuple arg

Open jepers opened this issue 10 years ago • 6 comments

Previous ID SR-294
Radar rdar://23163575
Original Reporter @jepers
Type Bug
Status Closed
Resolution Done

Environment

OS X 10.11.2, Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 69940d166c)

Additional Detail from JIRA
Votes 4
Component/s Compiler
Labels Bug
Assignee @AnthonyLatsis
Priority Medium

md5: 98ff25433ff92b7970173819af657d87

Issue Description:

prefix operator §{}
prefix func §(a: (Int, Int)) -> Int { return a.0 + a.1}
let a = (1, 2)
let b = §a // Error '§' is not a prefix unary operator
let c = (§)a // Error Consecutive statements on a line must be separated by ';'
let d = (§)(a) // OK
let e = §(1, 2) // Error '§' is not a prefix unary operator
let f = (§)(1, 2) // Error: Extra argument in call
let g = (§)((1, 2)) // OK

jepers avatar Dec 18 '15 00:12 jepers

Same result in Xcode 8 beta 3.

jepers avatar Jul 24 '16 08:07 jepers

In the Xcode 9.4.1 toolchain, it is the same result, with the following exceptions:

  • "Operator should no longer be declared with body"

  • `c` gained a warning: "Expression of type '(Int, Int)' is unused"

  • `f`'s error has changed to "Operator function '§' expects a single parameter of type '(Int, Int)'" with fixit, that works.

Dante-Broggi avatar Jul 16 '18 13:07 Dante-Broggi

I had forgot about this issue when I stumbled on it again but for postfix operators, wrote this post:
https://forums.swift.org/t/prefix-and-postfix-operators-not-working-for-tuple-types/17466
before I remembered this report.

jepers avatar Oct 29 '18 17:10 jepers

Comment by Jorge Juan (JIRA)

Same behaviour here: Xcode 10.1, Swift 4.2.1

This bug really needs a resolution.

swift-ci avatar Oct 31 '18 06:10 swift-ci

Looks like this was fixed recently alongside #19580, see this file. I'll add some more test cases to ensure this doesn't get accidentally broken again and we can then close the issue.

AnthonyLatsis avatar Nov 04 '18 19:11 AnthonyLatsis

#20346 The tests.

AnthonyLatsis avatar Nov 08 '18 03:11 AnthonyLatsis