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

Wrong receiver generic resolution on method call #21815

Closed
zuosixiaoxiongmao opened this issue Jul 6, 2024 · 1 comment · Fixed by #21833
Closed

Wrong receiver generic resolution on method call #21815

zuosixiaoxiongmao opened this issue Jul 6, 2024 · 1 comment · Fixed by #21833
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor.

Comments

@zuosixiaoxiongmao
Copy link

zuosixiaoxiongmao commented Jul 6, 2024

Describe the bug

field not found: NetworkServerSystemUdp

Reproduction Steps

pub type Entity = u64
type ComponentType = u16

pub struct Context {
pub mut:
        ecs &Ecs
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
pub struct EntityManager {
mut:
        living_entity_count u64
}

fn (mut self EntityManager) create_entity() Entity {
        entity := self.living_entity_count
        self.living_entity_count++
        return entity
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

pub interface ISystem {
        ecs &Ecs
mut:
        init()
}

pub struct System {
pub mut:
        ecs &Ecs
}

pub fn (mut self System) init() {
}

pub struct SystemManager {
mut:
        system_array map[string]ISystem = {}
}

fn (mut self SystemManager) add_system[T]() &T {
        mut t := T{}
        self.system_array[typeof[T]().name] = t
        return &t
}

////////////////////////////////////////////////////////////////////////////

@[heap]
pub struct Ecs {
mut:
        entity_manager EntityManager
        system_manager SystemManager
pub mut:
        root_entity Entity
}

pub fn Ecs.new() &Ecs {
        mut ecs := &Ecs{}
        ecs.root_entity = ecs.create_entity()
        return ecs
}

pub fn (mut self Ecs) create_entity() Entity {
        return self.entity_manager.create_entity()
}

pub fn (mut self Ecs) add_system[T]() {
        mut system := self.system_manager.add_system[T]()
        system.ecs = &self
        system.init()
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

struct NetworkUdpServerComponent {
}

struct NetworkServerSystemUdp {
        System
}

pub struct ConfigSystem {
        System
}

struct NetworkServerSystemUdpExt {
        NetworkServerSystemUdp
}

fn main() {
        mut ecs := Ecs.new()
        mut root_entity := ecs.create_entity()

        ecs.add_system[ConfigSystem]()
        ecs.add_system[NetworkServerSystemUdpExt]()

        // or
        // ecs.add_system<NetworkServerSystemUdpExt>()
        // ecs.add_system<ConfigSystem>()
}

Expected Behavior

build success

Current Behavior

builder error

Possible Solution

No response

Additional Information/Context

copy the code to lab.v file, and v ./lab.v. It will build error.

V version

0.4.6 1571645

Environment details (OS name and version, etc.)

windows

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.

@zuosixiaoxiongmao zuosixiaoxiongmao added the Bug This tag is applied to issues which reports bugs. label Jul 6, 2024
@JalonSolov
Copy link
Contributor

Compiling with -g options shows this:

/tmp/v_1000/../../../../../../home/jalon/lab.v:72: error: field not found: NetworkServerSystemUdp

@JalonSolov JalonSolov added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Jul 7, 2024
@felipensp felipensp added the Generics[T] Bugs/feature requests, that are related to the V generics. label Jul 9, 2024
@felipensp felipensp changed the title C error found. Wrong receiver generic resolution on method call Jul 9, 2024
@felipensp felipensp self-assigned this Jul 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. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants