Skip to content

Commit

Permalink
Fix spurious ambiguous call error (#1057)
Browse files Browse the repository at this point in the history
Bugs fixed:
- Fix issue where "call is ambiguous" could be reported attempting to call certain methods (closes #1056)

Technical:
- Add an additional kind of test ('project tests') that are built using MSBuild and can reference other projects and packages.
  • Loading branch information
degory authored Feb 13, 2024
1 parent 374a193 commit 7fbca6d
Show file tree
Hide file tree
Showing 22 changed files with 359 additions and 12 deletions.
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.1",
"version": "0.7.2",
"commands": [
"ghul-compiler"
]
Expand Down
39 changes: 36 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
name: ghul-compiler-package
path: ./nupkg/ghul.compiler.${{ needs.version.outputs.package }}.nupkg

tests:
integration_tests:
needs: [version, bootstrap]
name: Run tests

Expand Down Expand Up @@ -143,8 +143,41 @@ jobs:
name: test-results
path: test-results.txt

project_tests:
needs: [version, bootstrap]
name: Run project tests

runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/dotnet/sdk:8.0-jammy

timeout-minutes: 5

steps:
- uses: actions/checkout@v3

- name: Download ghul.compiler package
uses: actions/download-artifact@v4
with:
name: ghul-compiler-package
path: nupkg

- name: Install ghul.compiler
run: dotnet tool update --local ghul.compiler --version ${{ needs.version.outputs.package }} --add-source nupkg

- name: Restore local .NET tools
run: dotnet tool restore

- name: Run project tests
run: bash -c "set -o pipefail ; dotnet ghul-test --use-dotnet-build project-tests | tee project-test-results.txt"

- uses: actions/upload-artifact@v4
with:
name: project-test-results
path: project-test-results.txt

publish_beta_package:
needs: [version, unit_tests, tests]
needs: [version, unit_tests, integration_tests, project_tests]
name: Publish beta package

timeout-minutes: 5
Expand Down Expand Up @@ -286,7 +319,7 @@ jobs:
run: docker push degory/ghul-devcontainer:dotnet

publish_release_package:
needs: [version, unit_tests, container_tests]
needs: [version, unit_tests, project_tests, container_tests]
name: Publish release package

timeout-minutes: 5
Expand Down
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"dependsOn": [
"Pack"
],
"group": "build",
"presentation": {
"reveal": "silent",
"revealProblems": "onProblem",
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.6.21-alpha.1</Version>
<Version>0.7.3-alpha.51</Version>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -z "${ROOT}" ] ; then
ROOT=`pwd`
fi

echo root is ${ROOT}
echo will create test under "${ROOT}/integration-tests"

read -p "new test name (folder/kebab-case-test-name): " TEST_NAME

Expand Down
6 changes: 6 additions & 0 deletions project-tests/ambiguous-method-hiding-1/.vscode/ghul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
23 changes: 23 additions & 0 deletions project-tests/ambiguous-method-hiding-1/.vscode/tasks.json
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 --use-dotnet-build \"${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,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<GhulCompiler>dotnet ghul-compiler</GhulCompiler>
<AssemblyName>binary</AssemblyName>
</PropertyGroup>

<ItemGroup>
<GhulSources Include="**/*.ghul" />
<ProjectReference Include="../cs-test-assembly/cs-test-assembly.csproj" />
</ItemGroup>
</Project>
Empty file.
Empty file.
Empty file.
32 changes: 32 additions & 0 deletions project-tests/ambiguous-method-hiding-1/run.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
will call Base().method()...
---- Base.Method()
Base: from Base.Method()

will call Derived().method()...
>>>> OverrideSameReturnType.Method()
---- Base.Method()
<<<< OverrideSameReturnType.Method()
OverrideSameReturnType: from Base.Method() via OverrideSameReturnType.Method()

will call NewSameReturnType().method()...
---- NewSameReturnType.Method()
NewSameReturnType: from NewSameReturnType.Method()

will call NewVirtualSameReturnType().method()...
---- NewVirtualSameReturnType.Method()
NewVirtualSameReturnType: from NewVirtualSameReturnType.Method()

will call OverrideCovariantReturnType().method()...
>>>> OverrideCovariantReturnType.Method()
---- Base.Method()
<<<< OverrideCovariantReturnType.Method()
OverrideCovariantReturnType: from Base.Method() via OverrideCovariantReturnType.Method()

will call NewCovariantReturnType().method()...
---- NewCovariantReturnType.Method()
NewCovariantReturnType: from NewCovariantReturnType.Method()

will call NewVirtualCovariantReturnType().method()...
---- NewVirtualCovariantReturnType.Method()
NewVirtualCovariantReturnType: from NewVirtualCovariantReturnType.Method()

37 changes: 37 additions & 0 deletions project-tests/ambiguous-method-hiding-1/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Test is
use IO.Std.write_line;

use MethodHidingAndOverriding;

class Main is
entry() static is
write_line("will call Base().method()...");
write_line("Base: " + new Base().method());
write_line();

write_line("will call Derived().method()...");
write_line("OverrideSameReturnType: " + new OverrideSameReturnType().method());
write_line();

write_line("will call NewSameReturnType().method()...");
write_line("NewSameReturnType: " + new NewSameReturnType().method());
write_line();

write_line("will call NewVirtualSameReturnType().method()...");
write_line("NewVirtualSameReturnType: " + new NewVirtualSameReturnType().method());
write_line();

write_line("will call OverrideCovariantReturnType().method()...");
write_line("OverrideCovariantReturnType: " + new OverrideCovariantReturnType().method());
write_line();

write_line("will call NewCovariantReturnType().method()...");
write_line("NewCovariantReturnType: " + new NewCovariantReturnType().method());
write_line();

write_line("will call NewVirtualCovariantReturnType().method()...");
write_line("NewVirtualCovariantReturnType: " + new NewVirtualCovariantReturnType().method());
write_line();
si
si
si
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions project-tests/cs-test-assembly/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.sln
nupkg/
65 changes: 65 additions & 0 deletions project-tests/cs-test-assembly/cs-test-assembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace MethodHidingAndOverriding {
public class Base {
public virtual object? Method() {
System.Console.WriteLine("---- Base.Method()");
return "from Base.Method()";
}
}

public class OverrideSameReturnType: Base {
public override object? Method()
{
System.Console.WriteLine(">>>> OverrideSameReturnType.Method()");
var result = base.Method() + " via OverrideSameReturnType.Method()";
System.Console.WriteLine("<<<< OverrideSameReturnType.Method()");

return result;
}
}

public class NewSameReturnType: Base {
public new object? Method() {
System.Console.WriteLine("---- NewSameReturnType.Method()");

return "from NewSameReturnType.Method()";
}
}

public class NewVirtualSameReturnType: Base {
public virtual new object? Method() {
System.Console.WriteLine("---- NewVirtualSameReturnType.Method()");

return "from NewVirtualSameReturnType.Method()";
}
}

public class OverrideCovariantReturnType: Base {
public override string? Method()
{
System.Console.WriteLine(">>>> OverrideCovariantReturnType.Method()");
var result = base.Method() + " via OverrideCovariantReturnType.Method()";
System.Console.WriteLine("<<<< OverrideCovariantReturnType.Method()");

return result;
}
}

public class NewCovariantReturnType: Base {
public new string? Method() {
System.Console.WriteLine("---- NewCovariantReturnType.Method()");

return "from NewCovariantReturnType.Method()";
}
}

public class NewVirtualCovariantReturnType: Base {
public virtual new string? Method() {
System.Console.WriteLine("---- NewVirtualCovariantReturnType.Method()");

return "from NewVirtualCovariantReturnType.Method()";
}
}
}



14 changes: 14 additions & 0 deletions project-tests/cs-test-assembly/cs-test-assembly.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!-- <Version>1.0.4</Version> -->
<PackageOutputPath>./nupkg</PackageOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Remove="ghul.runtime" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/ioc/container.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ namespace IoC is

type_mapper = new Semantic.DotNet.TYPE_MAPPER(dotnet_symbol_table, innate_symbol_lookup, type_name_map, assemblies);

symbol_factory = new Semantic.DotNet.SYMBOL_FACTORY(namespaces, type_name_map, type_mapper, referenced_assemblies, assemblies);
symbol_factory = new Semantic.DotNet.SYMBOL_FACTORY(namespaces, type_name_map, type_mapper, referenced_assemblies, assemblies, logger);

assembly_info = new Semantic.DotNet.ASSEMBLY_INFO(ir_context);

Expand Down
Loading

0 comments on commit 7fbca6d

Please sign in to comment.