- Change typedef and const enums to not convert from literals by default. (#2934)

- Add `@constinit` to allow old typedef behaviour.
This commit is contained in:
Christoffer Lerno
2026-02-13 20:39:47 +01:00
committed by GitHub
parent bbf89815d6
commit e299a4b630
12 changed files with 37 additions and 19 deletions

View File

@@ -5,8 +5,8 @@ module std::hash::fnv32a;
typedef Fnv32a = uint;
const FNV32A_START @private = 0x811c9dc5;
const FNV32A_MUL @private = 0x01000193;
const FNV32A_START @private = (Fnv32a)0x811c9dc5;
const FNV32A_MUL @private = (Fnv32a)0x01000193;
macro void update(h, char x) @private => *h = (*h ^ ($typeof(*h))x) * FNV32A_MUL;
@@ -32,10 +32,10 @@ macro void Fnv32a.update_char(&self, char c)
fn uint hash(char[] data)
{
uint h = FNV32A_START;
Fnv32a h = FNV32A_START;
foreach (char x : data)
{
update(&h, x);
}
return h;
return (uint)h;
}

View File

@@ -5,10 +5,10 @@ module std::hash::fnv64a;
typedef Fnv64a = ulong;
const FNV64A_START @private = 0xcbf29ce484222325;
const FNV64A_MUL @private = 0x00000100000001b3;
const Fnv64a FNV64A_START @private = (Fnv64a)0xcbf29ce484222325;
const Fnv64a FNV64A_MUL @private = (Fnv64a)0x00000100000001b3;
macro void update(h, char x) @private => *h = (*h ^ ($typeof(*h))x) * FNV64A_MUL;
macro Fnv64a update(Fnv64a h, char x) @nodiscard @private => (h ^ (Fnv64a)x) * FNV64A_MUL;
fn void Fnv64a.init(&self)
{
@@ -20,22 +20,22 @@ fn void Fnv64a.update(&self, char[] data)
Fnv64a h = *self;
foreach (char x : data)
{
update(&h, x);
h = update(h, x);
}
*self = h;
}
macro void Fnv64a.update_char(&self, char c)
{
update(self, c);
*self = update(*self, c);
}
fn ulong hash(char[] data)
{
ulong h = FNV64A_START;
Fnv64a h = FNV64A_START;
foreach (char x : data)
{
update(&h, x);
h = update(h, x);
}
return h;
return (ulong)h;
}

View File

@@ -1,6 +1,6 @@
module std::os::win32 @if(env::WIN32) @link("shell32");
typedef Win32_REFKNOWNFOLDERID = Win32_KNOWNFOLDERID*;
alias Win32_REFKNOWNFOLDERID = Win32_KNOWNFOLDERID*;
typedef Win32_KNOWNFOLDERID = Win32_GUID;
extern fn Win32_HRESULT shGetKnownFolderPath(Win32_REFKNOWNFOLDERID rfid, Win32_DWORD dwFlags, Win32_HANDLE hToken, Win32_PWSTR* ppszPath) @cname("SHGetKnownFolderPath");

View File

@@ -8,9 +8,9 @@ typedef NativeThread = int;
fn void NativeOnceFlag.call_once(&flag, OnceFn func)
{
if (*flag == 0)
if (*flag == (NativeOnceFlag)0)
{
*flag = 1;
*flag = (NativeOnceFlag)1;
func();
}
}