Skip to content

Add a couple of regression tests #79910

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
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
113 changes: 113 additions & 0 deletions test/Constraints/bidirectional_conversions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// RUN: %target-typecheck-verify-swift
// REQUIRES: objc_interop

import Foundation
import CoreGraphics

/////////////

struct G<T> { // expected-note {{arguments to generic parameter 'T' ('CGFloat?' and 'CGFloat') are expected to be equal}}
var t: T
}

func foo1(x: (x: Int, y: Int)?, y: (Int, Int)) -> G<(x: Int, y: Int)> {
let g = G(t: x ?? y)
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 was the specific case that regressed with the deep equality change, but if you look at the rest of the file you'll see the general behavior with this sort of thing is quite inconsistent...

return g
}

func foo2(x: (Int, Int)?, y: (x: Int, y: Int)) -> G<(Int, Int)> {
let g = G(t: x ?? y)
return g
}

func foo3(x: (@convention(block) () -> ())?, y: @escaping () -> ()) -> G<@convention(block) () -> ()> {
let g = G(t: x ?? y)
return g
}

func foo4(x: (() -> ())?, y: @escaping @convention(block) () -> ()) -> G<() -> ()> {
let g = G(t: x ?? y)
return g
}

func foo5(x: CGFloat?, y: Double) -> G<CGFloat> {
let g = G(t: x ?? y)
// FIXME
return g // expected-error {{cannot convert return expression of type 'G<CGFloat?>' to return type 'G<CGFloat>'}}
}

func foo6(x: Double?, y: CGFloat) -> G<Double> {
let g = G(t: x ?? y)
return g
}

/////////////

func id<T>(_: T) -> T {}

func bar1(x: (x: Int, y: Int)) {
func f(_: (Int, Int)) {}
f(id(x))
}

func bar2(x: (Int, Int)) {
func f(_: (x: Int, y: Int)) {}
f(id(x))
}

func bar3(x: @escaping () -> ()) {
func f(_: @escaping @convention(block) () -> ()) {}
// FIXME
f(id(x)) // expected-error {{conflicting arguments to generic parameter 'T' ('@convention(block) () -> ()' vs. '() -> ()')}}
}

func bar4(x: @escaping @convention(block) () -> ()) {
func f(_: @escaping () -> ()) {}
// FIXME
f(id(x)) // expected-error {{conflicting arguments to generic parameter 'T' ('() -> ()' vs. '@convention(block) () -> ()')}}
}

func bar5(x: Double) {
func f(_: CGFloat) {}
f(id(x))
}

func bar6(x: CGFloat) {
func f(_: Double) {}
f(id(x))
}

/////////////

func unwrap<T>(_: T?) -> T {}

func baz1(x: (x: Int, y: Int)?) {
func f(_: (Int, Int)) {}
f(unwrap(x))
}

func baz2(x: (Int, Int)?) {
func f(_: (x: Int, y: Int)) {}
f(unwrap(x))
}

func baz3(x: (() -> ())?) {
func f(_: @escaping @convention(block) () -> ()) {}
f(unwrap(x))
}

func baz4(x: (@convention(block) () -> ())?) {
func f(_: @escaping () -> ()) {}
f(unwrap(x))
}

func baz5(x: Double?) {
func f(_: CGFloat) {}
f(unwrap(x))
}

func baz6(x: CGFloat?) {
func f(_: Double) {}
f(unwrap(x))
}

35 changes: 35 additions & 0 deletions validation-test/Sema/type_checker_perf/fast/swift_docc.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %target-typecheck-verify-swift -solver-scope-threshold=2000

// We don't use anything from Foundation below, but Foundation adds a
// large number of == overloads. Import it if we can, because it makes
// the problem instance harder.
#if canImport(Foundation)
import Foundation
#endif

struct Graph {
func nodeWithReference(_: Int) -> Node? { fatalError() }
}

struct DocumentationContext {
func parents(of: Int) -> [Int] { fatalError() }
var topicGraph: Graph
}

struct Node {
var reference: Int
var kind: Kind

enum Kind {
case tutorialTableOfContents
case chapter
case volume
}
}

func analyze(_ node: Node, context: DocumentationContext) {
_ = context.parents(of: node.reference)
.compactMap({ context.topicGraph.nodeWithReference($0) })
.first(where: { $0.kind == .tutorialTableOfContents || $0.kind == .chapter || $0.kind == .volume })
}