microsoft / microsoft/win32metadata

ConstantsScraper: Using `--with-type` with a constant that has a shift produces bad code

Open
#1,861 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.5k
Forks
149
Avg merge
5d 16h
Merged PRs (30d)
4

Description

Given a constant that is calculated with a shift:

```cpp
#define MY_CONST (1<<4)
```

Then trying to use `--with-type` with this constant (e.g., `--with-type=MY_CONST=ushort`), constants scraper will produce the following code:

```csharp
public const ushort MY_CONST = 1u<<4;
```

Which is invalid:

```
error CS0266: Cannot implicitly convert type 'uint' to 'ushort'. An explicit conversion exists (are you missing a cast?)
```

Contributor guide

Open the contributing guide

Research direction

Start at the constants scraper path handling the `--with-type` option and reproduce the issue with `#define MY_CONST (1<<4)` and `--with-type=MY_CONST=ushort`. Inspect the generated C# declaration and verify that the resulting code compiles without the uint-to-ushort error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.