Skip to content

wit, wit/bindgen: generate Go type aliases for WIT type aliases#205

Merged
ydnar merged 6 commits intomainfrom
ydnar/alias
Oct 9, 2024
Merged

wit, wit/bindgen: generate Go type aliases for WIT type aliases#205
ydnar merged 6 commits intomainfrom
ydnar/alias

Conversation

@ydnar
Copy link
Copy Markdown
Collaborator

@ydnar ydnar commented Oct 9, 2024

Go type aliases are now generated for each WIT type alias (type foo = bar). Deep chains of type aliases (type b = a; type c = b;) are fully supported. Generated documentation now reflects whether a type is an alias.

For example, given the following WIT:

package example:aliases;

interface i {
	resource r {
		m: func() -> u32;
	}

	type a = r;
	type b = a;
	type c = b;

	fa: func(v: a);
	fb: func(v: b);
	fc: func(v: c);
}

world w {
	import i;
	export i;
}

Generates the following Go:

// R represents the imported resource "example:aliases/i#r".
//
//	resource r
type R cm.Resource

// A represents the imported type alias "example:aliases/i#a".
//
// See [R] for more information.
type A = R

// B represents the imported type alias "example:aliases/i#b".
//
// See [A] for more information.
type B = A

// C represents the imported type alias "example:aliases/i#c".
//
// See [B] for more information.
type C = B

Fixes #204.

@ydnar ydnar self-assigned this Oct 9, 2024
@deadprogram
Copy link
Copy Markdown

Just verified that this PR does what it says it does. Thank you very much for such a quick response @ydnar

@ydnar ydnar merged commit 7544040 into main Oct 9, 2024
@ydnar ydnar deleted the ydnar/alias branch October 9, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

type alias declared in .wit file does not generate a named type

2 participants