The type system seems to be awkward in handling data location in tenery operation
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Description
Below is the reproducible program:
```solidity
contract A {
struct S {
int a;
}
S st;
function foo(S calldata sc) public {
S memory sm;
sm = sc; // pass
sm = st; // pass
sm = true ? sc : st; // fail: True expression's type struct A.S calldata does not match false expression's type struct A.S storage pointer
}
}
```
Seems that `st`'s type is lifted to a storage pointer and the pointer is incompatible with `sc`'s type calldata.
Is it an intentional behavior? Seems that the only workaround is writing a `if else` to avoid the ternery.
## Environment
- Compiler version: 0.8.28
Contributor guide
Research direction
Start by compiling the minimal contract A example with Solidity 0.8.28, focusing on the ternary expression in foo where calldata and storage are combined. Trace the compiler's type-checking and data-location handling for that expression; done means the intended behavior is established and the compiler no longer produces an incorrect or unexplained result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100