Skip to content
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

Calculated default polymorphic const of a struct is incorrect #4250

Open
zen3ger opened this issue Sep 16, 2024 · 0 comments
Open

Calculated default polymorphic const of a struct is incorrect #4250

zen3ger opened this issue Sep 16, 2024 · 0 comments

Comments

@zen3ger
Copy link
Contributor

zen3ger commented Sep 16, 2024

Context

Useful information to add to a bug report:

	Odin:    dev-2024-09:a16d3b6c9
	OS:      openSUSE Tumbleweed, Linux 6.10.7-1-default
	CPU:     AMD Ryzen 9 5900X 12-Core Processor            
	RAM:     31999 MiB
	Backend: LLVM 18.1.8

Expected Behavior

The default value calculated for a polymorphic constant will match what's calculated in a polymorphic procedure.

Current Behavior

The const values differ.

Failure Information (for bugs)

Reproduction:

package test

import "core:fmt"

LEN :: 64

S :: struct ($T, $U: typeid, $Count := LEN / max(size_of(T), size_of(U))) {}

make_s :: proc($T, $U: typeid) -> S(T, U, LEN / max(size_of(T), size_of(U))) {
	return {}
}

main :: proc() {
	wrong_count: S(f64, [2]int)
	correct_count := make_s(f64, [2]int)
	fmt.println("expected:", LEN / max(size_of(f64), size_of([2]int)))
	fmt.println("wrong:", wrong_count)
	fmt.println("correct:", correct_count)
}

Steps to Reproduce

  1. compile and run the reproduction
  2. See $Count differ in the print of wrong_count to the expected one.

Failure Logs

Output of the reproduction:

$ odin run .
expected: 4
wrong: S($T=f64, $U=[2]int, $Count=8){}
correct: S($T=f64, $U=[2]int, $Count=4){}
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

1 participant