JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.62k stars 5.48k forks source link

Structs not being accepted as function inputs #39957

Closed pjuangph closed 3 years ago

pjuangph commented 3 years ago

I have 3 files and two of them are modules. Connectivity.jl reads from Plot3D.jl

https://discourse.julialang.org/t/methoderror-no-method-matching-and-no-hints-either/56772

If you define a struct in Plot3D.jl called Block where Block is

    # Plot3D.jl
module Plot3D
    using Parameters

    @with_kw struct Block
        IMAX::Int64
        JMAX::Int64
        KMAX::Int64
        X::Array{Float64,3}
        Y::Array{Float64,3}
        Z::Array{Float64,3}
    end
end

Then you write a function in Connectivity.jl that uses the struct Block

module Connectivity 
    include("Plot3D.jl")  # somehow relative path has me doing this. Never had to do this in python
    using .Plot3D: Block
    function find_matching_blocks(block1::Block, block2::Block)
        print("testing")
        print("testing")
    end
end 

Calling find_matching_block(block1, block2). The expected behavior is you see testing printed out. What you get is actually an error without any helpful descriptions. Check the link.

What is the right way to do this and can somebody update the documentation?

simeonschaub commented 3 years ago

Are you including Plot3D.jl twice? Please include a full example and the error message in issues, I am having a hard time piecing this together from the link you posted.

pjuangph commented 3 years ago

Here you go. Simple example https://github.com/pjuangph/JuliaLearning

simeonschaub commented 3 years ago

Yes, you are including DataTestTypes.jl both in Connectivity.jl and run_me.jl, which creates separate modules with two different structs called Block. This is the expected behavior for include.

pjuangph commented 3 years ago

Where should remove it from? seems like it's needed everywhere.