-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated nil/closed channel and select edge cases
- Loading branch information
1 parent
abceba4
commit 2fe4c22
Showing
29 changed files
with
612 additions
and
39 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/Tests/Behavioral/ChannelReceiveFromClosed/ChannelReceiveFromClosed.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
18 changes: 18 additions & 0 deletions
18
src/Tests/Behavioral/ChannelReceiveFromClosed/ChannelReceivedFromClosed.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
src/Tests/Behavioral/ChannelReceiveFromClosed/ChannelReceivedFromClosed.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
12 changes: 12 additions & 0 deletions
12
src/Tests/Behavioral/ChannelReceiveFromNil/ChannelReceiveFromNil.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
89 changes: 89 additions & 0 deletions
89
src/Tests/Behavioral/ChannelReceiveFromNil/ChannelReceiveFromNil.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
8 changes: 8 additions & 0 deletions
8
src/Tests/Behavioral/ChannelReceiveFromNil/ChannelReceiveFromNil.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
src/Tests/Behavioral/ChannelSendToClosed/ChannelSendToClosed.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
89 changes: 89 additions & 0 deletions
89
src/Tests/Behavioral/ChannelSendToClosed/ChannelSendToClosed.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
src/Tests/Behavioral/ChannelSendToClosed/ChannelSendToClosed.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.