Skip to content

Commit 4e3fc04

Browse files
rcoreillyparalin
authored andcommitted
fix(compliance): add import_type_methods reproducer
Author: Randall C. O'Reilly <oreilly@ucdavis.edu> Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent e9d4f87 commit 4e3fc04

File tree

10 files changed

+191
-0
lines changed

10 files changed

+191
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package errlist
2+
3+
type ErrorList []string
4+
5+
func (p *ErrorList) Add(msg string) {
6+
*p = append(*p, msg)
7+
}
8+
9+
type AStruct struct {
10+
Msg string
11+
}
12+
13+
func (a *AStruct) Set(msg string) {
14+
a.Msg = msg
15+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Generated file based on errlist/errlist.go
2+
// Updated when compliance tests are re-run, DO NOT EDIT!
3+
4+
import * as $ from "@goscript/builtin/index.js";
5+
6+
export type ErrorList = $.Slice<string>;
7+
8+
export function ErrorList_Add(p: ErrorList, msg: string): void {
9+
p!.value = $.append(p!.value, msg)
10+
}
11+
12+
13+
export class AStruct {
14+
public get Msg(): string {
15+
return this._fields.Msg.value
16+
}
17+
public set Msg(value: string) {
18+
this._fields.Msg.value = value
19+
}
20+
21+
public _fields: {
22+
Msg: $.VarRef<string>;
23+
}
24+
25+
constructor(init?: Partial<{Msg?: string}>) {
26+
this._fields = {
27+
Msg: $.varRef(init?.Msg ?? "")
28+
}
29+
}
30+
31+
public clone(): AStruct {
32+
const cloned = new AStruct()
33+
cloned._fields = {
34+
Msg: $.varRef(this._fields.Msg.value)
35+
}
36+
return cloned
37+
}
38+
39+
public Set(msg: string): void {
40+
const a = this
41+
a.Msg = msg
42+
}
43+
44+
// Register this type with the runtime type system
45+
static __typeInfo = $.registerStructType(
46+
'AStruct',
47+
new AStruct(),
48+
[{ name: "Set", args: [{ name: "msg", type: { kind: $.TypeKind.Basic, name: "string" } }], returns: [] }],
49+
AStruct,
50+
{"Msg": { kind: $.TypeKind.Basic, name: "string" }}
51+
);
52+
}
53+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { AStruct } from "./errlist.gs.js"
2+
export type { ErrorList } from "./errlist.gs.js"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
error
2+
astruct
3+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"github.com/aperturerobotics/goscript/compliance/tests/import_type_methods/errlist"
5+
)
6+
7+
type parser struct {
8+
errors errlist.ErrorList
9+
astruct errlist.AStruct
10+
}
11+
12+
func main() {
13+
var p parser
14+
// this Add method does not work:
15+
p.errors.Add("error")
16+
println(p.errors[0])
17+
18+
// but it does work for a struct type:
19+
p.astruct.Set("astruct")
20+
println(p.astruct.Msg)
21+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Generated file based on import_type_methods.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 errlist from "@goscript/github.com/aperturerobotics/goscript/compliance/tests/import_type_methods/errlist/index.js"
7+
8+
export class parser {
9+
public get errors(): errlist.ErrorList {
10+
return this._fields.errors.value
11+
}
12+
public set errors(value: errlist.ErrorList) {
13+
this._fields.errors.value = value
14+
}
15+
16+
public get astruct(): errlist.AStruct {
17+
return this._fields.astruct.value
18+
}
19+
public set astruct(value: errlist.AStruct) {
20+
this._fields.astruct.value = value
21+
}
22+
23+
public _fields: {
24+
errors: $.VarRef<errlist.ErrorList>;
25+
astruct: $.VarRef<errlist.AStruct>;
26+
}
27+
28+
constructor(init?: Partial<{astruct?: errlist.AStruct, errors?: errlist.ErrorList}>) {
29+
this._fields = {
30+
errors: $.varRef(init?.errors ?? null as errlist.ErrorList),
31+
astruct: $.varRef(init?.astruct?.clone() ?? new errlist.AStruct())
32+
}
33+
}
34+
35+
public clone(): parser {
36+
const cloned = new parser()
37+
cloned._fields = {
38+
errors: $.varRef(this._fields.errors.value),
39+
astruct: $.varRef(this._fields.astruct.value?.clone() ?? null)
40+
}
41+
return cloned
42+
}
43+
44+
// Register this type with the runtime type system
45+
static __typeInfo = $.registerStructType(
46+
'parser',
47+
new parser(),
48+
[],
49+
parser,
50+
{"errors": "ErrorList", "astruct": "AStruct"}
51+
);
52+
}
53+
54+
export async function main(): Promise<void> {
55+
let p: parser = new parser()
56+
// this Add method does not work:
57+
errlist.ErrorList_Add(p.errors, "error")
58+
console.log(p.errors![0])
59+
60+
// but it does work for a struct type:
61+
p.astruct.Set("astruct")
62+
console.log(p.astruct.Msg)
63+
}
64+

compliance/tests/import_type_methods/index.ts

Whitespace-only changes.

compliance/tests/import_type_methods/skip-test

Whitespace-only changes.
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+
"baseUrl": ".",
5+
"lib": [
6+
"es2022",
7+
"esnext.disposable",
8+
"dom"
9+
],
10+
"module": "nodenext",
11+
"moduleResolution": "nodenext",
12+
"noEmit": true,
13+
"paths": {
14+
"@goscript/*": [
15+
"../../../gs/*",
16+
"../../../compliance/deps/*"
17+
],
18+
"@goscript/github.com/aperturerobotics/goscript/compliance/tests/import_type_methods/*": [
19+
"./*"
20+
]
21+
},
22+
"sourceMap": true,
23+
"target": "es2022"
24+
},
25+
"extends": "../../../tsconfig.json",
26+
"include": [
27+
"errlist/errlist.gs.ts",
28+
"errlist/index.ts",
29+
"import_type_methods.gs.ts",
30+
"index.ts"
31+
]
32+
}

0 commit comments

Comments
 (0)