Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type check issues #1064

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
"ghul.compiler": {
"version": "0.7.4",
"version": "0.7.5",
"commands": [
"ghul-compiler"
]
Expand Down
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"label": "Publish",
"type": "shell",
"command": "dotnet",
"group": "build",
"args": [
"publish",
"--output",
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.7.5-alpha.1</Version>
<Version>0.7.6-alpha.4</Version>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"other_flags": "--v3",
"compiler": "../../../bin/Release/net8.0/ghul",
"source": [
"."
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "../../../bin/Release/net8.0/ghul",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
thing_int: 5
thing_string: hello
thing_blah: Test.GenericClassArgumentsAreObjects.BLAH
obj: 5
obj: hello
obj: Test.GenericClassArgumentsAreObjects.BLAH
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Test.GenericClassArgumentsAreObjects is
use Collections;

use IO.Std.write_line;

class BLAH is
name: string;

init(name: string) is
self.name = name;
si
si

class THING[T] is
value: T;

init(value: T) is
self.value = value;
si

to_string() -> string is
// expect OK - to_string() is a method on all objects
return value.to_string();
si

to_object() -> object is
// expect OK - T should be assignable to object
return value;
si
si

entry() is
let thing_int = new THING[int](5);
let thing_string = new THING[string]("hello");
let thing_blah = new THING[BLAH](new BLAH("blah"));

write_line("thing_int: " + thing_int.to_string());
write_line("thing_string: " + thing_string.to_string());
write_line("thing_blah: " + thing_blah.to_string());

let obj: object;

obj = thing_int.to_object();
write_line("obj: " + obj.to_string());

obj = thing_string.to_object();
write_line("obj: " + obj.to_string());

obj = thing_blah.to_object();
write_line("obj: " + obj.to_string());
si
si
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>

<GhulCompiler>dotnet ghul-compiler</GhulCompiler>
</PropertyGroup>

<ItemGroup>
<GhulSources Include="**/*.ghul" />
<PackageReference Include="ghul.runtime" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "../../../bin/Release/net8.0/ghul",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--assembler
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ldarg.0
ldflda !0 class 'Test'.'GenericClassArgumentsAreObjects'.'THING' <!0> ::'_value'
constrained. !0
callvirt instance class ['System.Runtime']'System'.'String' class ['System.Runtime']'System'.'Object' ::'ToString'()
ret
ldarg.0
ldfld !0 class 'Test'.'GenericClassArgumentsAreObjects'.'THING' <!0> ::'_value'
box !0
ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Test.GenericClassArgumentsAreObjects is
use Collections;

use IO.Std.write_line;

class BLAH is
name: string;

init(name: string) is
self.name = name;
si
si

class THING[T] is
_value: T;

init(value: T) is
self._value = value;
si

to_string() -> string is
// expect OK - to_string() is a method on all objects

@IL.output("il.out")
return _value.to_string();
si

to_object() -> object is
// expect OK - T should be assignable to object

@IL.output("il.out")
return _value;
si
si

entry() is
si
si
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>

<GhulCompiler>dotnet ghul-compiler</GhulCompiler>
</PropertyGroup>

<ItemGroup>
<GhulSources Include="**/*.ghul" />
<PackageReference Include="ghul.runtime" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--dotnet
--dotnet
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ si
test_anon_function_arg_shadows_anon_function_arg() is
map([[1, 2, 3], [4, 5, 6]], x => map(x, x => x + 1));
si

entry() is
si
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>

<GhulCompiler>dotnet ghul-compiler</GhulCompiler>
</PropertyGroup>

<ItemGroup>
<GhulSources Include="**/*.ghul" />
<PackageReference Include="ghul.runtime" />
<PackageReference Include="ghul.pipes" />
<PackageReference Include="ghul.targets" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test.ghul: 10,13..10,20: error: no static overload found for sum(null, Ghul.int), tried Test.FunctionValueTypeArgumentsAreNotCompatibleWithNull.sum(a: int, b: int) -> Ghul.int
test.ghul: 11,13..11,23: error: no static overload found for sum(null, null), tried Test.FunctionValueTypeArgumentsAreNotCompatibleWithNull.sum(a: int, b: int) -> Ghul.int
test.ghul: 9,13..9,20: error: no static overload found for sum(Ghul.int, null), tried Test.FunctionValueTypeArgumentsAreNotCompatibleWithNull.sum(a: int, b: int) -> Ghul.int
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "../../../bin/Release/net8.0/ghul",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Test.FunctionValueTypeArgumentsAreNotCompatibleWithNull is
sum(a: int, b: int) -> int is
return a + b;
si

entry() is
sum(1, 2); // OK

sum(1, null); // Error: null is not compatible with int
sum(null, 2); // Error: null is not compatible with int
sum(null, null); // Error: null is not compatible with int
si
si
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
test.ghul: 37,13..37,18: error: T is not assignable to Ghul.int
test.ghul: 38,13..38,18: error: U is not assignable to Ghul.string
test.ghul: 43,13..43,18: error: Test.Main.X is not assignable to Ghul.int
test.ghul: 44,13..44,18: error: Test.Main.Y is not assignable to Ghul.string
test.ghul: 46,13..46,30: error: Ghul.object is not assignable to T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,38 @@ namespace Test is
let x: X;
let y: Y;

i = t;
j = u;
i = t; // expect error T is not an int
j = u; // expect error U is not a string

t.to_string();
x.to_string();

i = x;
j = y;
i = x; // expect error X is not an int
j = y; // expect error Y is not a string

t = new object();
u = new object();
t = new object(); // expect error object is not a T
u = new object(); // expect error object is not a U

x = new object();
y = new object();
x = new object(); // expect error object is not a X
y = new object(); // expect error object is not a Y

i = new object();
j = new object();
i = new object(); // expect error object is not an int
j = new object(); // expect error object is not a string

t = 10;
y = "hello";
t = 10; // expect error int is not a T
y = "hello"; // expect error string is not a Y

let o: object;
let p: object;

o = x;
p = y;
o = x; // OK X is an object
p = y; // OK Y is an object

o = t;
p = u;
o = t; // OK T is an object
p = u; // OK U is an object

let w: T = o;
let z: U = p;
let w: T = o; // expect error object is not a T
let z: U = p; // expect error object is not a U
si
si
si
Loading
Loading