Skip to content

Changes related to SE-0028 #255

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

Merged
merged 1 commit into from
Feb 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1538,10 +1538,10 @@ public class NSDateComponents : NSObject, NSCopying, NSSecureCoding {
yearForWeekOfYear = value
break
case NSCalendarUnit.Calendar:
print(".Calendar cannot be set via \(__FUNCTION__)")
print(".Calendar cannot be set via \(#function)")
break
case NSCalendarUnit.TimeZone:
print(".TimeZone cannot be set via \(__FUNCTION__)")
print(".TimeZone cannot be set via \(#function)")
break
default:
break
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSObjCRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ public typealias NSComparator = (AnyObject, AnyObject) -> NSComparisonResult

public let NSNotFound: Int = Int.max

@noreturn internal func NSRequiresConcreteImplementation(fn: String = __FUNCTION__, file: StaticString = __FILE__, line: UInt = __LINE__) {
@noreturn internal func NSRequiresConcreteImplementation(fn: String = #function, file: StaticString = #file, line: UInt = #line) {
fatalError("\(fn) must be overriden in subclass implementations", file: file, line: line)
}

@noreturn internal func NSUnimplemented(fn: String = __FUNCTION__, file: StaticString = __FILE__, line: UInt = __LINE__) {
@noreturn internal func NSUnimplemented(fn: String = #function, file: StaticString = #file, line: UInt = #line) {
fatalError("\(fn) is not yet implemented", file: file, line: line)
}

@noreturn internal func NSInvalidArgument(message: String, method: String = __FUNCTION__, file: StaticString = __FILE__, line: UInt = __LINE__) {
@noreturn internal func NSInvalidArgument(message: String, method: String = #function, file: StaticString = #file, line: UInt = #line) {
fatalError("\(method): \(message)", file: file, line: line)
}

Expand Down
6 changes: 3 additions & 3 deletions TestFoundation/TestNSAffineTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ class TestNSAffineTransform : XCTestCase {
]
}

func checkPointTransformation(transform: NSAffineTransform, point: NSPoint, expectedPoint: NSPoint, _ message: String = "", file: StaticString = __FILE__, line: UInt = __LINE__) {
func checkPointTransformation(transform: NSAffineTransform, point: NSPoint, expectedPoint: NSPoint, _ message: String = "", file: StaticString = #file, line: UInt = #line) {
let newPoint = transform.transformPoint(point)
XCTAssertEqualWithAccuracy(Double(newPoint.x), Double(expectedPoint.x), accuracy: accuracyThreshold, file: file, line: line,
"x (expected: \(expectedPoint.x), was: \(newPoint.x)): \(message)")
XCTAssertEqualWithAccuracy(Double(newPoint.y), Double(expectedPoint.y), accuracy: accuracyThreshold, file: file, line: line,
"y (expected: \(expectedPoint.y), was: \(newPoint.y)): \(message)")
}

func checkSizeTransformation(transform: NSAffineTransform, size: NSSize, expectedSize: NSSize, _ message: String = "", file: StaticString = __FILE__, line: UInt = __LINE__) {
func checkSizeTransformation(transform: NSAffineTransform, size: NSSize, expectedSize: NSSize, _ message: String = "", file: StaticString = #file, line: UInt = #line) {
let newSize = transform.transformSize(size)
XCTAssertEqualWithAccuracy(Double(newSize.width), Double(expectedSize.width), accuracy: accuracyThreshold, file: file, line: line,
"width (expected: \(expectedSize.width), was: \(newSize.width)): \(message)")
XCTAssertEqualWithAccuracy(Double(newSize.height), Double(expectedSize.height), accuracy: accuracyThreshold, file: file, line: line,
"height (expected: \(expectedSize.height), was: \(newSize.height)): \(message)")
}

func checkRectTransformation(transform: NSAffineTransform, rect: NSRect, expectedRect: NSRect, _ message: String = "", file: StaticString = __FILE__, line: UInt = __LINE__) {
func checkRectTransformation(transform: NSAffineTransform, rect: NSRect, expectedRect: NSRect, _ message: String = "", file: StaticString = #file, line: UInt = #line) {
let newRect = transform.transformRect(rect)

checkPointTransformation(transform, point: newRect.origin, expectedPoint: expectedRect.origin, file: file, line: line,
Expand Down
6 changes: 3 additions & 3 deletions TestFoundation/TestNSRegularExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestNSRegularExpression : XCTestCase {
]
}

func simpleRegularExpressionTestWithPattern(patternString: String, target searchString: String, looking: Bool, match: Bool, file: StaticString = __FILE__, line: UInt = __LINE__) {
func simpleRegularExpressionTestWithPattern(patternString: String, target searchString: String, looking: Bool, match: Bool, file: StaticString = #file, line: UInt = #line) {
do {
let str = searchString.bridge()
var range = NSMakeRange(0, str.length)
Expand Down Expand Up @@ -159,7 +159,7 @@ class TestNSRegularExpression : XCTestCase {
simpleRegularExpressionTestWithPattern("\\\\\\|\\(\\)\\[\\{\\~\\$\\*\\+\\?\\.", target:"\\|()[{~$*+?.", looking:true, match:true)
}

func replaceRegularExpressionTest(patternString: String, _ patternOptions: NSRegularExpressionOptions, _ searchString: String, _ searchOptions: NSMatchingOptions, _ searchRange: NSRange, _ templ: String, _ numberOfMatches: Int, _ result: String, file: StaticString = __FILE__, line: UInt = __LINE__) {
func replaceRegularExpressionTest(patternString: String, _ patternOptions: NSRegularExpressionOptions, _ searchString: String, _ searchOptions: NSMatchingOptions, _ searchRange: NSRange, _ templ: String, _ numberOfMatches: Int, _ result: String, file: StaticString = #file, line: UInt = #line) {
do {
let regex = try NSRegularExpression(pattern: patternString, options: patternOptions)
let mutableString = searchString.bridge().mutableCopy() as! NSMutableString
Expand Down Expand Up @@ -198,7 +198,7 @@ class TestNSRegularExpression : XCTestCase {
replaceRegularExpressionTest("\\b(th[a-z]+) \\1\\b", .CaseInsensitive, "This this is the the way.", [], NSMakeRange(0, 25), "*\\\\\\$1*", 2, "*\\$1* is *\\$1* way.")
}

func complexRegularExpressionTest(patternString: String, _ patternOptions: NSRegularExpressionOptions, _ searchString: String, _ searchOptions: NSMatchingOptions, _ searchRange: NSRange, _ numberOfMatches: Int, _ firstMatchOverallRange: NSRange, _ firstMatchFirstCaptureRange: NSRange, _ firstMatchLastCaptureRange: NSRange, file: StaticString = __FILE__, line: UInt = __LINE__) {
func complexRegularExpressionTest(patternString: String, _ patternOptions: NSRegularExpressionOptions, _ searchString: String, _ searchOptions: NSMatchingOptions, _ searchRange: NSRange, _ numberOfMatches: Int, _ firstMatchOverallRange: NSRange, _ firstMatchFirstCaptureRange: NSRange, _ firstMatchLastCaptureRange: NSRange, file: StaticString = #file, line: UInt = #line) {
do {
let regex = try NSRegularExpression(pattern: patternString, options: patternOptions)
let matches = regex.matchesInString(searchString, options: searchOptions, range: searchRange)
Expand Down
18 changes: 9 additions & 9 deletions TestFoundation/TestNSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ struct ComparisonTest {

init(
_ lhs: String, _ rhs: String,
reason: String = "", line: UInt = __LINE__
reason: String = "", line: UInt = #line
) {
self.lhs = lhs
self.rhs = rhs
Expand Down Expand Up @@ -1039,8 +1039,8 @@ func checkHasPrefixHasSuffix(lhs: String, _ rhs: String, _ stack: [UInt]) -> Int
}

var failures = 0
failures += testFailure(expectHasPrefix, lhs.hasPrefix(rhs), stack + [__LINE__])
failures += testFailure(expectHasSuffix, lhs.hasSuffix(rhs), stack + [__LINE__])
failures += testFailure(expectHasPrefix, lhs.hasPrefix(rhs), stack + [#line])
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't compile for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems [#line] doesn't compile but [ #line] does. Intentional as part of SE-0028?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This includes keeping __FUNCTION__, and making #line have the dual behavior of being a directive when it is the first token on a line, but an expression otherwise.

From SE-0028
So if #line is taken as expression it looks like it should work. Or i'm missing something.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm - @lattner ?

Copy link
Contributor

Choose a reason for hiding this comment

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

This was fixed in a follow on patch. Just put a space between the [ and # if you don't have a build with the fix yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

failures += testFailure(expectHasSuffix, lhs.hasSuffix(rhs), stack + [#line])
return failures
}

Expand All @@ -1049,16 +1049,16 @@ extension TestNSString {
#if !_runtime(_ObjC)
for test in comparisonTests {
var failures = 0
failures += checkHasPrefixHasSuffix(test.lhs, test.rhs, [test.loc, __LINE__])
failures += checkHasPrefixHasSuffix(test.rhs, test.lhs, [test.loc, __LINE__])
failures += checkHasPrefixHasSuffix(test.lhs, test.rhs, [test.loc, #line])
failures += checkHasPrefixHasSuffix(test.rhs, test.lhs, [test.loc, #line])

let fragment = "abc"
let combiner = "\u{0301}"

failures += checkHasPrefixHasSuffix(test.lhs + fragment, test.rhs, [test.loc, __LINE__])
failures += checkHasPrefixHasSuffix(fragment + test.lhs, test.rhs, [test.loc, __LINE__])
failures += checkHasPrefixHasSuffix(test.lhs + combiner, test.rhs, [test.loc, __LINE__])
failures += checkHasPrefixHasSuffix(combiner + test.lhs, test.rhs, [test.loc, __LINE__])
failures += checkHasPrefixHasSuffix(test.lhs + fragment, test.rhs, [test.loc, #line])
failures += checkHasPrefixHasSuffix(fragment + test.lhs, test.rhs, [test.loc, #line])
failures += checkHasPrefixHasSuffix(test.lhs + combiner, test.rhs, [test.loc, #line])
failures += checkHasPrefixHasSuffix(combiner + test.lhs, test.rhs, [test.loc, #line])

let fail = (failures > 0)
if fail {
Expand Down