Skip to content
Open
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
28 changes: 28 additions & 0 deletions Samples/NestedType/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/struct.dll",
"args": [],
"cwd": "${workspaceFolder}/bin/Debug/",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "integratedTerminal",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
24 changes: 24 additions & 0 deletions Samples/NestedType/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
4 changes: 4 additions & 0 deletions Samples/NestedType/NestedType.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
10
10
100
100
29 changes: 29 additions & 0 deletions Samples/NestedType/NestedType.pys
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
struct Rect
{
var p1: Vector2Int
var p2: Vector2Int

struct Vector2Int
{
var x : int
var y : int
}
}


function main()
{
var rect = Rect()
//rect.p1 = Rect.Vector2Int()
rect.p1.x = 10
/*
rect.p1.y = 10
rect.p2.x = 100
rect.p2.y = 100

print(rect.p1.x)
print(rect.p1.y)
print(rect.p2.x)
print(rect.p2.y)
//*/
}
6 changes: 6 additions & 0 deletions Samples/NestedType/NestedType.pysproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/Compiler.Tests.Samples/ConsoleOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ConsoleOutputTests(ITestOutputHelper output)
[InlineData("IsEven", "2", "10", "5")]
[InlineData("Enum")]
[InlineData("Struct")]
//[InlineData("NestedType")]
public async Task SamplesTests(string filenamePrefix, params string[] inputs)
{
var psi = new ProcessStartInfo
Expand Down
182 changes: 173 additions & 9 deletions src/Compiler.Tests/CodeAnalysis/Syntax/Binding/BinderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Compiler.CodeAnalysis;
using Compiler.CodeAnalysis.Diagnostics;
using Compiler.CodeAnalysis.Symbols;
Expand Down Expand Up @@ -606,6 +605,30 @@ function main()
};
AssertDiagnostics(text, diagnostics);
}

[Fact]
public void Binder_MemberAccess_Reports_UnexpectedToken()
{
var text = @"
struct TestStruct
{
}

function main()
{
TestStruct. [=] 10
TestStruct.[(][)]
}
";

var diagnostics = new List<string>()
{
DiagnosticCode.UnexpectedToken.GetDiagnostic(SyntaxKind.EqualsToken, SyntaxKind.IdentifierToken),
DiagnosticCode.UnexpectedToken.GetDiagnostic(SyntaxKind.OpenParenthesisToken, SyntaxKind.IdentifierToken),
DiagnosticCode.UnexpectedToken.GetDiagnostic(SyntaxKind.CloseParenthesisToken, SyntaxKind.IdentifierToken)
};
AssertDiagnostics(text, diagnostics);
}

[Fact]
public void Binder_NameExpression_Reports_NoErrorForInsertedToken()
Expand Down Expand Up @@ -703,7 +726,7 @@ public void Binder_Parameter_Already_Declared()
var text = @"
function sum(a: int, b: int, [a: int]) : int
{
return a + b + c
return a + b
}
";

Expand Down Expand Up @@ -919,20 +942,20 @@ public void Binder_MultiLineComment_ReportsUnterminated()
}

[Fact]
public void Binder_Cannot_Access_Member()
public void Binder_MemberAccess_Reports_CannotAccessMember()
{
const string? text = @"
function main()
{
var p: int = 0
p.[length] = 10
p.[length()]
p.[length]()
}
";
var diagnostics = new List<string>()
{
DiagnosticCode.CannotAccessMember.GetDiagnostic("length", "int"),
DiagnosticCode.CannotAccessMember.GetDiagnostic("length", "int"),
DiagnosticCode.UndefinedFunction.GetDiagnostic("length"),
};
AssertDiagnostics(text, diagnostics);
}
Expand Down Expand Up @@ -1095,6 +1118,33 @@ function main()
AssertDiagnostics(text, diagnostics);
}

[Fact]
public void Binder_MemberAccess_Nested_Reports_CannotAccessMember()
{
var text = @"
struct Point
{
}

struct Line
{
var start: Point
}

function main()
{
var nested = Line()
var x = nested.start.[x]
}
";

var diagnostics = new List<string>()
{
DiagnosticCode.CannotAccessMember.GetDiagnostic("x", "Point"),
};
AssertDiagnostics(text, diagnostics);
}

[Fact]
public void Binder_MemberAccess_NestedCall()
{
Expand Down Expand Up @@ -1239,8 +1289,12 @@ struct TestStruct
function f(i : int)
{
print(b)
print(self.a + 1)
print(i)
g()
}

function g()
{

}
}
";
Expand Down Expand Up @@ -1276,7 +1330,7 @@ function f()

AssertDiagnostics(text, diagnostics);
}

[Fact]
public void Binder_SelfExpression_Reports_CannotUseSelfOutsideOfReceiverFunctions()
{
Expand Down Expand Up @@ -1365,6 +1419,90 @@ enum TestEnum
AssertDiagnostics(text, diagnostics);
}

[Fact]
public void Binder_TypeDeclaration_NestedType()
{
var text = @"
struct Line
{
var p1 : Point
var p2 : Point

struct Point
{
var x : int
var y : int
}
}";

var diagnostics = new List<string>()
{
};

AssertDiagnostics(text, diagnostics);
}

[Fact]
public void Binder_VariableDeclaration_NestedType()
{
var text = @"
struct Line
{
var p1 : Point
var p2 : Point

struct Point
{
var x : int
var y : int

struct Point1
{
}
}
}

function main()
{
var p = Line.Point.Point1()
}";

var diagnostics = new List<string>()
{
};

AssertDiagnostics(text, diagnostics);
}

[Fact]
public void Binder_MemberAccess_NestedType()
{
var text = @"
struct Line
{
var p1 : Point
var p2 : Point

struct Point
{
var x : int
var y : int
}
}

function main()
{
var line = Line()
line.p1.x = 10
}";

var diagnostics = new List<string>()
{
};

AssertDiagnostics(text, diagnostics);
}

/*
[Fact]
public void Binder_IfStatement_Reports_UnreachableCode_Warning()
Expand Down Expand Up @@ -1475,6 +1613,32 @@ function a(x : string)

}
}
";

var diagnostics = new List<string>()
{
};

AssertDiagnostics(text, diagnostics);
}


[Fact]
public void Binder_MemberAccess_SupportsOverloading()
{
var text = @"
struct TestStruct
{
function a(x : int)
{
a(string(x))
}

function a(x : string)
{

}
}

function main()
{
Expand Down
Loading