Skip to content

TinyGo Panics on Generic Type Aliases #4819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Yeaseen opened this issue Mar 19, 2025 · 3 comments
Open

TinyGo Panics on Generic Type Aliases #4819

Yeaseen opened this issue Mar 19, 2025 · 3 comments

Comments

@Yeaseen
Copy link

Yeaseen commented Mar 19, 2025

TinyGo crashes when compiling a generic type alias, even when using GODEBUG=gotypesalias=1. Though I am not sure whether TinyGo supports generic type aliases correctly.

$ cat test.go
package main
import "fmt"
// Define a generic type
type Wrapper[T any] struct {
	Value T
}
// Alias declaration with type parameter
type Alias[T any] = Wrapper[T]

func main() {
	// Using the alias
	var a Alias[int] = Alias[int]{Value: 42}
	fmt.Println("a:", a.Value)
}
GODEBUG=gotypesalias=1 tinygo run test.go
panic: unknown type: main.Alias[int]

goroutine 200 [running]:
github.com/tinygo-org/tinygo/compiler.(*compilerContext).makeLLVMType(0xc003bb2000?, {0x7020428?, 0xc00287d340?})
        /__w/tinygo/tinygo/compiler/compiler.go:468 +0x539
@gandarez
Copy link

gandarez commented Mar 20, 2025

It produces different errors when setting target.

Without target set

GODEBUG=gotypesalias=1 tinygo run main.go

panic: unknown type: sync.Mutex

goroutine 54 [running]:
github.com/tinygo-org/tinygo/compiler.(*compilerContext).makeLLVMType(0x14001ca8000?, {0x10aa97468?, 0x1400587a800?})
        /Users/runner/work/tinygo/tinygo/compiler/compiler.go:468 +0x578

With pico2-w target set

GODEBUG=gotypesalias=1 tinygo run -target=pico2-w main.go

panic: unknown type: any

goroutine 116 [running]:
github.com/tinygo-org/tinygo/compiler.(*compilerContext).makeLLVMType(0x1400af8a280?, {0x10b4ab468?, 0x140000221c0?})
        /Users/runner/work/tinygo/tinygo/compiler/compiler.go:468 +0x578

Even though changing it from any to int return the same result panic: unknown type: any.

@eliasnaur
Copy link
Contributor

Probable dupe: #4416

@ofauchon
Copy link
Contributor

ofauchon commented Apr 1, 2025

Hello.

Same behaviour with ArchLinux (and llvm19 packages)

$ pacman -Q llvm 
llvm 19.1.7-1

$ cd tinygo
$ git switch dev
$ git pull --recurse-submodules
$ rm -fr llvm-project
$ make llvm-source
$ go install 

$ tinygo version
tinygo version 0.38.0-dev-91e20a53 linux/amd64 (using go version go1.24.1 and LLVM version 19.1.7)

$ cat main.go 
package main
func main() {
        println("Hello")
}

$ tinygo clean
$ tinygo build -target=pico 
panic: unknown type: internal/task.Uint32

goroutine 87 [running]:
github.com/tinygo-org/tinygo/compiler.(*compilerContext).makeLLVMType(0xc007890640?, {0xa9f528?, 0xc003123800?})
	/home/olivier/dev/contrib/tinygo/compiler/compiler.go:468 +0x539
github.com/tinygo-org/tinygo/compiler.(*compilerContext).getLLVMType(0xc007890640, {0xa9f528, 0xc003123800})
	/home/olivier/dev/contrib/tinygo/compiler/compiler.go:383 +0x65
github.com/tinygo-org/tinygo/compiler.(*compilerContext).createDIType(0xc007890640, {0xa9f528, 0xc003123800})
	/home/olivier/dev/contrib/tinygo/compiler/compiler.go:496 +0x3a

$ GODEBUG=gotypesalias=0 tinygo build
=> Compilation OK 

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

No branches or pull requests

4 participants