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

compile-time reflection error for enum/struct declared in other module #20948

Closed
mac-hel opened this issue Mar 3, 2024 · 1 comment · Fixed by #20988
Closed

compile-time reflection error for enum/struct declared in other module #20948

mac-hel opened this issue Mar 3, 2024 · 1 comment · Fixed by #20988
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Comptime Features processed during compile time, like $if, $for, $env etc Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).

Comments

@mac-hel
Copy link
Contributor

mac-hel commented Mar 3, 2024

Describe the bug

compile time looping over enum/struct fields throws compiler error
if enum/struct is declared in other module

Reproduction Steps

module_a/
    my_data.v
main.v

my_data.v

module module_a

pub enum MyEnumModule {
  raz
  dwa
}

pub struct MyStructModule {
	id string
	costam int
}

main.v

import net.http;
import module_a

enum MyEnumTop {
  raz
  dwa
}

struct MyStructTop {
  id string
  costam int
}

fn main() {

  // enum/struct declared in same file no issues:
  $for field in MyStructTop.fields {
    println(field.name);
  }
  $for method_val in MyEnumTop.values {
    println(method_val.name);
  }

  // enum/struct declared in other module errors:

  // ERROR:
  $for field in module_a.MyStructModule.fields {
    println(field.name);
  }

  // ERROR:
  $for method_val in module_a.MyEnumModule.values {
    println(method_val.name);
  }

  // ERROR:
  $for method_val in http.Method.values {
    println(method_val.name);
  }
}

Expected Behavior

compile, print enum/struct's fields

Current Behavior

compile time error:

>> v run main.v                                                                                                                                                                                                        
            main.v:27:26: error: unknown kind `MyStructModule`, available are: `methods`, `fields`, `values`, `variants` or `attributes`                                                                                           
               25 |                                                                                                                                                                                                                            
               26 |   // ERROR:                                                                                                                                                                                                                
               27 |   $for field in module_a.MyStructModule.fields {                                                                                                                                                                           
                  |                          ~~~~~~~~~~~~~~                                                                                                                                                                                    
               28 |     println(field.name);                                                                                                                                                                                                   
               29 |   }    

Possible Solution

No response

Additional Information/Context

Trying to work arround this with type EnumAlias = module_a.MyEnumModule and iterating over alias also gives error, but this time its builder error

V version

V 0.4.4 ac9b724

Environment details (OS name and version, etc.)

V full version: V 0.4.4 f603035.ac9b724
OS: linux, "EndeavourOS Linux"
Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz

getwd: /H/_nobackup/Projects/v_errors/v_compiletime_for_enum
vexe: /H/_nobackup/mh/.local/share/v/v
vexe mtime: 2024-03-03 14:33:21

vroot: OK, value: /H/_nobackup/mh/.local/share/v
VMODULES: OK, value: /home/mh/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.44.0
Git vroot status: weekly.2024.06-140-gac9b724b
.git/config present: true

CC version: cc (GCC) 13.2.1 20230801
thirdparty/tcc status: thirdparty-linux-amd64 99683af0

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@mac-hel mac-hel added the Bug This tag is applied to issues which reports bugs. label Mar 3, 2024
@mac-hel
Copy link
Contributor Author

mac-hel commented Mar 3, 2024

possibly related: #20787 ?

@felipensp felipensp added Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Comptime Features processed during compile time, like $if, $for, $env etc Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones). labels Mar 5, 2024
@felipensp felipensp self-assigned this Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Comptime Features processed during compile time, like $if, $for, $env etc Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants