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

Undefined identifier error for generic type argument #754

Open
taichi-ishitani opened this issue Jun 5, 2024 · 2 comments
Open

Undefined identifier error for generic type argument #754

taichi-ishitani opened this issue Jun 5, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@taichi-ishitani
Copy link
Contributor

taichi-ishitani commented Jun 5, 2024

Veryl reports an undefined identifier error for a generic type argument pointing a type locally defined.
For exmaple:

package PackageA {
  function FuncA::<T> -> T {
    var a: T;
    a = 0;
    return a;
  }
}

module ModuleA {
  type my_logic = logic;
  let _a: logic = PackageA::FuncA::<my_logic>();
}

image

@dalance dalance added the bug Something isn't working label Jun 5, 2024
@taichi-ishitani
Copy link
Contributor Author

To get valid generated SV code, the original type declaration need to be copied to the generated package declaration.

@dalance
Copy link
Collaborator

dalance commented Aug 16, 2024

This is a known restriction. ref: https://doc.veryl-lang.org/book/05_language_reference/14_generics.html

Additionally, the actual parameters should be accessible at the position of the generics declaration. For example, module names can be used as actual parameters because it is accessible through the whole project. On the other hand, local parameters can’t be used as actual parameters in many cases. This is caused by that the local parameters is not accessible from the potision of the generics declaration.

The above case should be written like below:

package PackageA {
  type my_logic = logic;
  function FuncA::<T> -> T {
    var a: T;
    a = 0;
    return a;
  }
}

module ModuleA {
  let _a: logic = PackageA::FuncA::<PackageA::my_logic>();
}

Copying the type declaration will not work fine in many cases like below:

module ModuleA #(
  param my_logic: type = logic,
) {
  let _a: logic = PackageA::FuncA::<my_logic>();
}

module ModuleA #(
  param TYPE: type = logic,
) {
  type my_logic = TYPE;
  let _a: logic = PackageA::FuncA::<my_logic>();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants