- $typefrom now also accepts a constant string, and so works like $evaltype.

- `$evaltype` is deprecated in favour of `$typefrom`.
This commit is contained in:
Christoffer Lerno
2025-06-03 14:51:56 +02:00
parent 8fc01d4e1a
commit 9645bd3289
10 changed files with 101 additions and 22 deletions

View File

@@ -38,11 +38,11 @@ fn void main()
x++;
$counter++;
$endif
$if $defined($evaltype("Foo").$eval("ab")):
$if $defined($typefrom("Foo").$eval("ab")):
x++;
$counter++;
$endif
$if $defined($evaltype("mymodule::Foo").$eval("bob")):
$if $defined($typefrom("mymodule::Foo").$eval("bob")):
x++;
$counter++;
$endif

View File

@@ -10,11 +10,11 @@ int b;
fn void main()
{
printf("%s\n", Foo.qnameof);
printf("%s\n", $evaltype("Foo").qnameof);
printf("%s\n", $typefrom("Foo").qnameof);
printf("%s\n", Foo.nameof);
printf("%s\n", $evaltype("mymodule::Foo").nameof);
printf("%s\n", $typefrom("mymodule::Foo").nameof);
printf("%s\n", Foo.extnameof);
printf("%s\n", $evaltype("Foo").extnameof);
printf("%s\n", $typefrom("Foo").extnameof);
printf("%s\n", $qnameof(b));
printf("%s\n", $qnameof($eval("b")));

View File

@@ -11,10 +11,10 @@ fn void main2()
fn void main3()
{
$evaltype("int").extnameof; // #error: 'int' does not have a property or method 'extnameof'
$typefrom("int").extnameof; // #error: 'int' does not have a property or method 'extnameof'
}
fn void main4()
{
$evaltype("foo::int").extnameof; // #error: Only valid types may be resolved with $evaltype.
$typefrom("foo::int").extnameof; // #error: Only valid types can be resolved with $typefrom
}

View File

@@ -3,17 +3,17 @@ import bar;
import bar::abc;
long x = Baz.sizeof;
short y = $evaltype("Baz").sizeof;
short y = $typefrom("Baz").sizeof;
int z = bar::Baz.sizeof;
int w = bar::Baz.sizeof;
int v = bar::abc::Foo.sizeof;
int x1 = $sizeof(x);
int y1 = $sizeof($eval("y"));
int a = Baz.y.sizeof;
int b = $evaltype("Deep").a.$eval("b").sizeof;
int b = $typefrom("Deep").a.$eval("b").sizeof;
int c = Deep.a.b.c.sizeof;
int d = Deep[][100].sizeof;
int e = $evaltype("Deep")[][100]**[100][]*.sizeof;
int e = $typefrom("Deep")[][100]**[100][]*.sizeof;
int a2 = Baz.y.sizeof;
int a3 = Baz.y.sizeof;
int a4 = Baz.y.sizeof;

View File

@@ -8,7 +8,7 @@ fn void a()
fn void b()
{
int x = $evaltype("Bazz").sizeof; // #error: 'Bazz' could not be found, did you spell it rig
int x = $typefrom("Bazz").sizeof; // #error: 'Bazz' could not be found, did you spell it rig
}
@@ -19,17 +19,17 @@ fn void e()
fn void f()
{
int x = $evaltype("bar::Bazy").sizeof; // #error: 'bar::Bazy' could not be found
int x = $typefrom("bar::Bazy").sizeof; // #error: 'bar::Bazy' could not be found
}
fn void g()
{
int x = $evaltype("bar::").sizeof; // #error: Only valid types may be resolved with $evaltype
int x = $typefrom("bar::").sizeof; // #error: Only valid types can be resolved with $typefrom
}
fn void k()
{
int v = $evaltype("int").x.sizeof; // #error: 'x'.
int v = $typefrom("int").x.sizeof; // #error: 'x'.
}
fn void l()