odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.89k stars 606 forks source link

matrix type cannot be used in parapoly #3009

Open edyu opened 11 months ago

edyu commented 11 months ago

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

        Odin: dev-2023-11:04244041
        OS:   Ubuntu 22.04.3 LTS, Linux 5.15.133.1-microsoft-standard-WSL2
        CPU:  12th Gen Intel(R) Core(TM) i7-12700H
        RAM:  15838 MiB

Expected Behavior

Please describe the behavior you are expecting

field_matrix :: proc(
    $N: int,
) -> (
    result: matrix[N, N]int,
) {
  return
}

or

field_matrix :: proc(
    $N: int,
) -> (
    result: matrix[N, N]int,
) where N <= 4 {
  return
}

should both work. The following without matrix however does work

field_matrix :: proc(
    $N: int,
) -> (
    result: [N][N]int,
) {
  return
}

works

Current Behavior

compiler would complain

Error: Invalid matrix row count, expected 1+ rows, got N
        ) -> matrix[N, N]int {
Error: Invalid matrix column count, expected 1+ rows, got N
        ) -> matrix[N, N]int {

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Use matrix in parapoly function declaration
  2. Compile
  3. Won't compile

Failure Logs

Please include any relevant log snippets or files here.

xtactis commented 11 months ago

I also found that the following is allowed, so it seems that this bug only happens inside the declaration

field_matrix :: proc($N: int) -> any where N <= 4 {
    result: matrix[N, N]int
    return result
}
xtactis commented 11 months ago

Found some more interesting behavior... This is not legal

field_matrix :: proc($N: int, m: matrix[N, N]int) -> int where N <= 4 {
    return N
}

But this IS legal and used in the core library

field_matrix :: proc(m: matrix[$N, N]int) -> int where N <= 4 {
    return N
}

I'm currently trying to debug this and I'm not sure how this happens yet as I'm not too familiar with the codebase

theb1rd commented 8 months ago

I encountered this one just now. It was the second procedure I ever wrote in Odin, in first hour of experimentation. Couldn't figure out what I was doing wrong. My luck :)