Skip to content

Commit

Permalink
Updated nil/closed channel and select edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchiecarroll committed Jan 7, 2025
1 parent abceba4 commit 2fe4c22
Show file tree
Hide file tree
Showing 29 changed files with 612 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<RootNamespace>go</RootNamespace>
<AssemblyName>ChannelReceiveFromClosed</AssemblyName>
<Product>go2cs</Product>
<Version>0.1.4</Version>
<Description>$(AssemblyName) ($(TargetFramework) - $(Configuration))</Description>
<AssemblyTitle>$(Description)</AssemblyTitle>
<Copyright>Copyright © 2025</Copyright>
<Authors>$(Product) Authors</Authors>
<Company>Grid Protection Alliance</Company>
<RepositoryUrl>https://github.com/GridProtectionAlliance/go2cs</RepositoryUrl>
<ApplicationIcon>go2cs.ico</ApplicationIcon>
<Nullable>enable</Nullable>
<NoWarn>660;661;IDE1006;CS8981</NoWarn>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(OutDir)'==''">
<OutDir>bin\$(Configuration)\$(TargetFramework)\</OutDir>
</PropertyGroup>

<!-- Enable native compiled output optimizations -->
<PropertyGroup>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishTrimmed>True</PublishTrimmed>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>

<!-- Setup packaging options for library projects -->
<PropertyGroup Condition="'$(OutputType)'=='Library'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>go.$(AssemblyName)</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageDescription>$(Description) -- C# project converted from Go source</PackageDescription>
<PackageProjectUrl>https://github.com/GridProtectionAlliance/go2cs</PackageProjectUrl>
<PackageIcon>go2cs.png</PackageIcon>
<PackageTags>$(AssemblyName);go2cs;Golang;go</PackageTags>
</PropertyGroup>

<ItemGroup Condition="'$(OutputType)'=='Library'">
<None Include="go2cs.png" Pack="true" PackagePath="" Visible="false" />
<None Include="go2cs.ico" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<!-- Expose output of source generators as local files -->
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
<ProjectReference Include="..\..\..\go2cs.CodeGenerators\go2cs.CodeGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="All" />
</ItemGroup>

<!-- Define Go type aliases -->
<ItemGroup>
<Using Include="go.builtin" Static="True" />
<Using Include="System" />
<Using Include="System.Byte" Alias="uint8" />
<Using Include="System.UInt16" Alias="uint16" />
<Using Include="System.UInt32" Alias="uint32" />
<Using Include="System.UInt64" Alias="uint64" />
<Using Include="System.SByte" Alias="int8" />
<Using Include="System.Int16" Alias="int16" />
<Using Include="System.Int32" Alias="int32" />
<Using Include="System.Int64" Alias="int64" />
<Using Include="System.Single" Alias="float32" />
<Using Include="System.Double" Alias="float64" />
<Using Include="System.Numerics.Complex" Alias="complex128" />
<Using Include="System.Int32" Alias="rune" />
<Using Include="System.UIntPtr" Alias="uintptr" />
<Using Include="System.Numerics.BigInteger" Alias="GoUntyped" />
<Using Include="System.ComponentModel.DescriptionAttribute" Alias="GoTag" />
</ItemGroup>

<ItemGroup>
<!-- TODO: Add references to required projects -->
<ProjectReference Include="..\..\..\gocore\golib\golib.csproj" />
<ProjectReference Include="..\..\..\gocore\fmt\fmt.csproj" />
<ProjectReference Include="..\..\..\gocore\math\math.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace go;

using fmt = fmt_package;

public static partial class main_package {

private static void Main() {
var c = new channel<nint>(3);
c.ᐸꟷ(1);
c.ᐸꟷ(2);
c.ᐸꟷ(3);
close(c);
for (nint i = 0; i < 4; i++) {
fmt.Printf("%d "u8, ᐸꟷ(c));
}
}

} // end main_package
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import "fmt"

func main() {
c := make(chan int, 3)
c <- 1
c <- 2
c <- 3
close(c)
for i := 0; i < 4; i++ {
fmt.Printf("%d ", <-c) // prints 1 2 3 0
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace go;

using fmt = fmt_package;

public static partial class main_package {

private static void Main() {
channel<@string> c = default;
fmt.Println(ᐸꟷ(c));
}

} // end main_package
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<RootNamespace>go</RootNamespace>
<AssemblyName>ChannelReceiveFromNil</AssemblyName>
<Product>go2cs</Product>
<Version>0.1.4</Version>
<Description>$(AssemblyName) ($(TargetFramework) - $(Configuration))</Description>
<AssemblyTitle>$(Description)</AssemblyTitle>
<Copyright>Copyright © 2025</Copyright>
<Authors>$(Product) Authors</Authors>
<Company>Grid Protection Alliance</Company>
<RepositoryUrl>https://github.com/GridProtectionAlliance/go2cs</RepositoryUrl>
<ApplicationIcon>go2cs.ico</ApplicationIcon>
<Nullable>enable</Nullable>
<NoWarn>660;661;IDE1006;CS8981</NoWarn>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(OutDir)'==''">
<OutDir>bin\$(Configuration)\$(TargetFramework)\</OutDir>
</PropertyGroup>

<!-- Enable native compiled output optimizations -->
<PropertyGroup>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishTrimmed>True</PublishTrimmed>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>

<!-- Setup packaging options for library projects -->
<PropertyGroup Condition="'$(OutputType)'=='Library'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>go.$(AssemblyName)</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageDescription>$(Description) -- C# project converted from Go source</PackageDescription>
<PackageProjectUrl>https://github.com/GridProtectionAlliance/go2cs</PackageProjectUrl>
<PackageIcon>go2cs.png</PackageIcon>
<PackageTags>$(AssemblyName);go2cs;Golang;go</PackageTags>
</PropertyGroup>

<ItemGroup Condition="'$(OutputType)'=='Library'">
<None Include="go2cs.png" Pack="true" PackagePath="" Visible="false" />
<None Include="go2cs.ico" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<!-- Expose output of source generators as local files -->
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
<ProjectReference Include="..\..\..\go2cs.CodeGenerators\go2cs.CodeGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="All" />
</ItemGroup>

<!-- Define Go type aliases -->
<ItemGroup>
<Using Include="go.builtin" Static="True" />
<Using Include="System" />
<Using Include="System.Byte" Alias="uint8" />
<Using Include="System.UInt16" Alias="uint16" />
<Using Include="System.UInt32" Alias="uint32" />
<Using Include="System.UInt64" Alias="uint64" />
<Using Include="System.SByte" Alias="int8" />
<Using Include="System.Int16" Alias="int16" />
<Using Include="System.Int32" Alias="int32" />
<Using Include="System.Int64" Alias="int64" />
<Using Include="System.Single" Alias="float32" />
<Using Include="System.Double" Alias="float64" />
<Using Include="System.Numerics.Complex" Alias="complex128" />
<Using Include="System.Int32" Alias="rune" />
<Using Include="System.UIntPtr" Alias="uintptr" />
<Using Include="System.Numerics.BigInteger" Alias="GoUntyped" />
<Using Include="System.ComponentModel.DescriptionAttribute" Alias="GoTag" />
</ItemGroup>

<ItemGroup>
<!-- TODO: Add references to required projects -->
<ProjectReference Include="..\..\..\gocore\golib\golib.csproj" />
<ProjectReference Include="..\..\..\gocore\fmt\fmt.csproj" />
<ProjectReference Include="..\..\..\gocore\math\math.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "fmt"

func main() {
var c chan string
fmt.Println(<-c) // deadlock
}
Binary file not shown.
23 changes: 23 additions & 0 deletions src/Tests/Behavioral/ChannelSendToClosed/ChannelSendToClosed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace go;

using fmt = fmt_package;

public static partial class main_package {

private static void Main() {
channel<nint> c = new channel<nint>(100);
for (nint i = 0; i < 10; i++) {
var cʗ1 = c;
goǃ(() => {
for (nint j = 0; j < 10; j++) {
cʗ1.ᐸꟷ(j);
}
close(cʗ1);
});
}
foreach (var i in c) {
fmt.Println(i);
}
}

} // end main_package
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<RootNamespace>go</RootNamespace>
<AssemblyName>ChannelSendToClosed</AssemblyName>
<Product>go2cs</Product>
<Version>0.1.4</Version>
<Description>$(AssemblyName) ($(TargetFramework) - $(Configuration))</Description>
<AssemblyTitle>$(Description)</AssemblyTitle>
<Copyright>Copyright © 2025</Copyright>
<Authors>$(Product) Authors</Authors>
<Company>Grid Protection Alliance</Company>
<RepositoryUrl>https://github.com/GridProtectionAlliance/go2cs</RepositoryUrl>
<ApplicationIcon>go2cs.ico</ApplicationIcon>
<Nullable>enable</Nullable>
<NoWarn>660;661;IDE1006;CS8981</NoWarn>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(OutDir)'==''">
<OutDir>bin\$(Configuration)\$(TargetFramework)\</OutDir>
</PropertyGroup>

<!-- Enable native compiled output optimizations -->
<PropertyGroup>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishTrimmed>True</PublishTrimmed>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
</PropertyGroup>

<!-- Setup packaging options for library projects -->
<PropertyGroup Condition="'$(OutputType)'=='Library'">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>go.$(AssemblyName)</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageDescription>$(Description) -- C# project converted from Go source</PackageDescription>
<PackageProjectUrl>https://github.com/GridProtectionAlliance/go2cs</PackageProjectUrl>
<PackageIcon>go2cs.png</PackageIcon>
<PackageTags>$(AssemblyName);go2cs;Golang;go</PackageTags>
</PropertyGroup>

<ItemGroup Condition="'$(OutputType)'=='Library'">
<None Include="go2cs.png" Pack="true" PackagePath="" Visible="false" />
<None Include="go2cs.ico" Pack="true" PackagePath="" Visible="false" />
</ItemGroup>

<!-- Expose output of source generators as local files -->
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
<ProjectReference Include="..\..\..\go2cs.CodeGenerators\go2cs.CodeGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="All" />
</ItemGroup>

<!-- Define Go type aliases -->
<ItemGroup>
<Using Include="go.builtin" Static="True" />
<Using Include="System" />
<Using Include="System.Byte" Alias="uint8" />
<Using Include="System.UInt16" Alias="uint16" />
<Using Include="System.UInt32" Alias="uint32" />
<Using Include="System.UInt64" Alias="uint64" />
<Using Include="System.SByte" Alias="int8" />
<Using Include="System.Int16" Alias="int16" />
<Using Include="System.Int32" Alias="int32" />
<Using Include="System.Int64" Alias="int64" />
<Using Include="System.Single" Alias="float32" />
<Using Include="System.Double" Alias="float64" />
<Using Include="System.Numerics.Complex" Alias="complex128" />
<Using Include="System.Int32" Alias="rune" />
<Using Include="System.UIntPtr" Alias="uintptr" />
<Using Include="System.Numerics.BigInteger" Alias="GoUntyped" />
<Using Include="System.ComponentModel.DescriptionAttribute" Alias="GoTag" />
</ItemGroup>

<ItemGroup>
<!-- TODO: Add references to required projects -->
<ProjectReference Include="..\..\..\gocore\golib\golib.csproj" />
<ProjectReference Include="..\..\..\gocore\fmt\fmt.csproj" />
<ProjectReference Include="..\..\..\gocore\math\math.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/Tests/Behavioral/ChannelSendToClosed/ChannelSendToClosed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import "fmt"

func main() {
var c = make(chan int, 100)
for i := 0; i < 10; i++ {
go func() {
for j := 0; j < 10; j++ {
c <- j
}
close(c)
}()
}
for i := range c {
fmt.Println(i)
}
}
Binary file not shown.
10 changes: 10 additions & 0 deletions src/Tests/Behavioral/ChannelSendToNil/ChannelSendToNil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace go;

public static partial class main_package {

private static void Main() {
channel<@string> c = default;
c.ᐸꟷ("let's get started"u8);
}

} // end main_package
Loading

0 comments on commit 2fe4c22

Please sign in to comment.