Not all data types can be converted to String using string interpolation
- Dominant language
- Rust
- Stars
- 1k
- Forks
- 212
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 65
Description
**Describe the bug**
Not all data types can be converted to String using string interpolation. I've noticed this for UDTs, with both named and unnamed items, there might be other types affected. This also means that certain types of type-parameterized functions can no longer be implemented, compared to Q# 0.*.
**To Reproduce**
The following code doesn't work for UDTs:
```
newtype AnonymousPair = (Int, Bool);
newtype NamedPair = (First : Int, Second : Bool);
let ap = AnonymousPair(1, false);
let np = NamedPair(2, true);
Message($"UDT with anonymous items = {ap}");
Message($"UDT with named items = {np}");
```
(If I unwrap them, though, using `ap!` and `np!`, the resulting tuples will be printed)
The following type-parameterized function used to work in Q# 0.* but fails to compile now.
```qsharp
/// # Summary
/// A function that converts an argument to a string
/// and appends a prefix to it.
function ToStringWithPrefix<'T>(
a : 'T,
prefix : String
) : String {
return $"{prefix} {a}";
}
```
**Expected behavior**
I expect any Q# type to be convertible to String via string interpolation.
**System information**
- QDK 1.0.33
Contributor guide
Research direction
Start by reproducing the two UDT interpolation examples and the generic ToStringWithPrefix function with QDK 1.0.33. Trace the Q# string-interpolation type-checking and conversion path, then verify that both named and unnamed UDTs and the type-parameterized function compile and produce strings as expected.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100