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

Segmentation fault #4208

Closed
ivarne opened this issue Sep 4, 2013 · 4 comments
Closed

Segmentation fault #4208

ivarne opened this issue Sep 4, 2013 · 4 comments
Assignees

Comments

@ivarne
Copy link
Sponsor Member

ivarne commented Sep 4, 2013

On the latest julia build I get this:

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http:https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" to list help topics
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.2.0-prerelease+3619
 _/ |\__'_|_|_|\__'_|  |  Commit 57a04d4* 2013-09-04 05:25:04 UTC
|__/                   |  x86_64-apple-darwin12.4.0

julia> abstract c

julia> type a
       a::Int64
       end

julia> type b
       a::Int64
       end

julia> function d(a::c)
       print(a.a)
       end
# methods for generic function d
d(a::c) at none:2

julia> d(a(5))
Segmentation fault: 11

Should this code work, and give me a function d that works on both a and b? My impression is that it should at least not segfault, and jeff usually fix these issues really fast.

@kmsquire
Copy link
Member

kmsquire commented Sep 4, 2013

More minimal version:

julia> type a
         a
       end

julia> a(5)
Segmentation fault (core dumped)

You probably shouldn't have the type and variable be the same name, but it shouldn't segfault.

@kmsquire
Copy link
Member

kmsquire commented Sep 4, 2013

Also, if you want types a and b to be subtypes of c, you should specify them as such:

abstract C

type A <: C
   n::Int64
end

type B <: C
   n::Int64
end

d(a::C) = print(a.n)

julia> d(A(5))
5

As a convention, types in Julia also have capital letters, so they can be distinguished more easily from variables.

@ivarne
Copy link
Sponsor Member Author

ivarne commented Sep 4, 2013

Thank you for pointing out the dump part of the issue. I did not remember to add the <: c when I retyped the example after rebuilding julia. Using capital letters is definitely a good convention, but as the variable naming suggest I was just using the alphabet and julia does not enforce that convention.

@kmsquire
Copy link
Member

kmsquire commented Sep 4, 2013

Yep, just a convention! It also might explain why this issue hasn't been noticed before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants