Skip to content

Commit a7768f2

Browse files
committed
fix: export select case from reflect gs package
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent 3602454 commit a7768f2

File tree

8 files changed

+76
-17
lines changed

8 files changed

+76
-17
lines changed

compliance/tests/package_import_reflect/actual.log

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cases len: 1
2+
First case dir: 3
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import "reflect"
4+
5+
func main() {
6+
// Test creating reflect.SelectCase struct literals
7+
cases := []reflect.SelectCase{
8+
{Dir: reflect.SelectDefault},
9+
}
10+
println("Cases len:", len(cases))
11+
println("First case dir:", cases[0].Dir)
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Generated file based on struct_literal_interface.go
2+
// Updated when compliance tests are re-run, DO NOT EDIT!
3+
4+
import * as $ from "@goscript/builtin/index.js"
5+
6+
import * as reflect from "@goscript/reflect/index.js"
7+
8+
export async function main(): Promise<void> {
9+
// Test creating reflect.SelectCase struct literals
10+
let cases = $.arrayToSlice<reflect.SelectCase>([$.markAsStructValue(new reflect.SelectCase({Dir: reflect.SelectDefault}))])
11+
console.log("Cases len:", $.len(cases))
12+
console.log("First case dir:", cases![0].Dir)
13+
}
14+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"compilerOptions": {
3+
"allowImportingTsExtensions": true,
4+
"lib": [
5+
"es2022",
6+
"esnext.disposable",
7+
"dom"
8+
],
9+
"module": "nodenext",
10+
"moduleResolution": "nodenext",
11+
"noEmit": true,
12+
"paths": {
13+
"*": [
14+
"./*"
15+
],
16+
"@goscript/*": [
17+
"../../../gs/*",
18+
"../../../compliance/deps/*"
19+
],
20+
"@goscript/github.com/aperturerobotics/goscript/compliance/tests/struct_literal_interface/*": [
21+
"./*"
22+
]
23+
},
24+
"sourceMap": true,
25+
"target": "es2022"
26+
},
27+
"extends": "../../../tsconfig.json",
28+
"include": [
29+
"index.ts",
30+
"struct_literal_interface.gs.ts"
31+
]
32+
}

gs/reflect/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ export {
3737
StructTag,
3838
StructField,
3939
ValueError,
40-
SelectDir,
4140
SelectSend,
4241
SelectRecv,
4342
SelectDefault,
43+
SelectCase,
4444
bitVector,
4545
} from './types.js'
4646
export type {
4747
uintptr,
4848
Pointer,
4949
Method,
50-
SelectCase,
50+
SelectDir,
5151
SliceHeader,
5252
StringHeader,
5353
MapIter,

gs/reflect/types.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,24 @@ export interface Channel<T = unknown> {
106106
}
107107

108108
// Select case for channel operations
109-
export interface SelectCase {
110-
Dir: SelectDir
111-
Chan?: Value // Value representing a channel - optional since default cases don't need it
112-
Send?: Value // Value to send (if Dir is SendDir) - optional since only needed for send cases
113-
}
114-
115-
// Select direction constants
116-
export class SelectDir {
117-
constructor(private _value: number) {}
109+
export class SelectCase {
110+
public Dir!: SelectDir
111+
public Chan?: Value // Value representing a channel - optional since default cases don't need it
112+
public Send?: Value // Value to send (if Dir is SendDir) - optional since only needed for send cases
118113

119-
valueOf(): number {
120-
return this._value
114+
constructor(init?: Partial<SelectCase>) {
115+
if (init) {
116+
Object.assign(this, init)
117+
}
121118
}
122119
}
123120

124-
export const SelectSend = new SelectDir(1)
125-
export const SelectRecv = new SelectDir(2)
126-
export const SelectDefault = new SelectDir(3)
121+
// Select direction constants - SelectDir is just an int in Go
122+
export type SelectDir = number
123+
124+
export const SelectSend: SelectDir = 1
125+
export const SelectRecv: SelectDir = 2
126+
export const SelectDefault: SelectDir = 3
127127

128128
// Slice header (internal representation)
129129
export interface SliceHeader {

0 commit comments

Comments
 (0)