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-14146] String(describing:) doesn't respect types refined for Swift #56525

Open
drewcrawford opened this issue Feb 2, 2021 · 2 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@drewcrawford
Copy link
Contributor

Previous ID SR-14146
Radar rdar://problem/73985903
Original Reporter @drewcrawford
Type Bug
Environment

Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
Target: x86_64-apple-darwin20.3.0

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 0454bb06990c4e8c35df50d6ae961891

Issue Description:

If I call String(describing: ) on an instance of trivial struct type, it prints a call to the constructor. Ex.,

struct ExampleSwiftStruct {
    let exampleMember: Float
}

print("\(String(describing: ExampleSwiftStruct(exampleMember: 2)))") //ExampleSwiftStruct(exampleMember: 2.0)

(I think this behavior is technically unspecified, but it's a very useful behavior for printing problematic values and then pasting them into playgrounds or unit tests.)

However in the case that the type was refined for Swift, the behavior is a bit odd

__attribute__((swift_name("ExampleCStruct")))
typedef struct {
    __attribute__((swift_name("exampleMember")))
    float unrefinedCMember;
    
} UnrefinedCType;

prints

UnrefinedCType(exampleMember: 2.0)

e.g. with the unrefined name as the type being constructed, but the refined name of the member.

Ideally, Swift would use the refined name in both places. It's possible to provide custom implementations of the appropriate protocols and then get defined behavior, but for debugging the large universe of C types it's not an ideal situation.

@typesanitizer
Copy link

@swift-ci create

@lorentey
Copy link
Member

This matches how the type instance is printed:

```
print(ExampleCStruct.self) // ⟹ UnrefinedCType
```

Changing this could be tricky – I expect it comes from demangling, and that loses the the imported name.

@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. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants