mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix bug with defer assignment in macro #1807.
This commit is contained in:
11
test/test_suite/macros/typed_hash_access.c3
Normal file
11
test/test_suite/macros/typed_hash_access.c3
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
macro void @foo(int #a)
|
||||
{
|
||||
var x = float.#a; // #error: cannot already be resolved
|
||||
}
|
||||
|
||||
fn void main()
|
||||
{
|
||||
int inf;
|
||||
@foo(inf);
|
||||
}
|
||||
45
test/test_suite/statements/defer_hash.c3t
Normal file
45
test/test_suite/statements/defer_hash.c3t
Normal file
@@ -0,0 +1,45 @@
|
||||
import std::io;
|
||||
|
||||
struct Version {
|
||||
uint major;
|
||||
uint minor;
|
||||
}
|
||||
|
||||
fn void main()
|
||||
{
|
||||
String s = "123.456";
|
||||
|
||||
Version v;
|
||||
v.major = @read_int(s);
|
||||
s = s[1..];
|
||||
v.minor = @read_int(s);
|
||||
|
||||
io::printfn("Version{.major = %d, .minor = %d}", v.major, v.minor);
|
||||
}
|
||||
|
||||
<*
|
||||
@require values::@is_lvalue(#s)
|
||||
*>
|
||||
macro int @read_int(String #s)
|
||||
{
|
||||
int res = 0;
|
||||
int i = 0;
|
||||
|
||||
String s = #s;
|
||||
defer #s = s[i..]; // commenting out this lines leads to a successful compilation
|
||||
|
||||
while (i < s.len && s[i].is_space())
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
if (i >= s.len) return res;
|
||||
|
||||
char c;
|
||||
while (i < s.len && (c = s[i]).is_digit())
|
||||
{
|
||||
res = (10 * res) + (c - '0');
|
||||
++i;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user