<p dir="auto">The following consistently causes a segfault in 0.4 final release (as well as 0.4-rc1), and the same line of gf.c.   I created a branch of ApproxFun that shows the bug.  Note that the <code class="notranslate">--check-bounds=yes</code> appears necessary to reproduce.</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Pkg.add(&quot;ApproxFun&quot;)
Pkg.checkout(&quot;ApproxFun&quot;,&quot;bug-segfaultjl&quot;)"><pre class="notranslate">Pkg<span class="pl-k">.</span><span class="pl-c1">add</span>(<span class="pl-s"><span class="pl-pds">"</span>ApproxFun<span class="pl-pds">"</span></span>)
Pkg<span class="pl-k">.</span><span class="pl-c1">checkout</span>(<span class="pl-s"><span class="pl-pds">"</span>ApproxFun<span class="pl-pds">"</span></span>,<span class="pl-s"><span class="pl-pds">"</span>bug-segfaultjl<span class="pl-pds">"</span></span>)</pre></div>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="[Macintosh:~/.julia/v0.4/ApproxFun/test] solver% julia --check-bounds=yes
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type &quot;?help&quot; for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.0 (2015-10-08 06:20 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-apple-darwin13.4.0

julia&gt; versioninfo()
Julia Version 0.4.0
Commit 0ff703b* (2015-10-08 06:20 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

julia&gt; using ApproxFun

julia&gt; x=Fun(identity,[-1.,1.])
Fun([0.0,1.0],Chebyshev(【-1.0,1.0】))

julia&gt; f=x+sin(2x)*sqrt(1-x^2)

signal (11): Segmentation fault: 11
jl_method_table_assoc_exact at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:251
jl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1663
maxspace at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Space.jl:230
union at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Space.jl:297
isconvertible at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Space.jl:311
jlcall_isconvertible_22217 at  (unknown line)
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1691
sumspacecoefficients at /Users/solver/.julia/v0.4/ApproxFun/src/Spaces/Modifier/Modifier.jl:102
coefficients at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Fun.jl:45
call at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/constructors.jl:54
jlcall_call_22211 at  (unknown line)
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1691
+ at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Fun.jl:181
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1691
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:55
eval at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:213
eval at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:219
eval_body at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:592
jl_toplevel_eval_body at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:527
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:521
jl_toplevel_eval_in at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/builtins.c:579
eval_user_input at REPL.jl:62
jlcall_eval_user_input_21258 at  (unknown line)
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1325
anonymous at REPL.jl:92
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/task.c:241
Segmentation fault: 11```


"><pre class="notranslate">[Macintosh<span class="pl-k">:</span><span class="pl-k">~</span><span class="pl-k">/</span><span class="pl-k">.</span>julia<span class="pl-k">/</span>v0.<span class="pl-c1">4</span><span class="pl-k">/</span>ApproxFun<span class="pl-k">/</span>test] solver<span class="pl-k">%</span> julia <span class="pl-k">--</span>check<span class="pl-k">-</span>bounds<span class="pl-k">=</span>yes
               _
   _       _ <span class="pl-c1">_</span>(_)_     <span class="pl-k">|</span>  A fresh approach to technical computing
  (_)     <span class="pl-k">|</span> (_) (_)    <span class="pl-k">|</span>  Documentation<span class="pl-k">:</span> http<span class="pl-k">:</span><span class="pl-k">//</span>docs<span class="pl-k">.</span>julialang<span class="pl-k">.</span>org
   _ _   _<span class="pl-k">|</span> <span class="pl-k">|</span>_  __ _   <span class="pl-k">|</span>  Type <span class="pl-s"><span class="pl-pds">"</span>?help<span class="pl-pds">"</span></span> <span class="pl-k">for</span> help.
  <span class="pl-k">|</span> <span class="pl-k">|</span> <span class="pl-k">|</span> <span class="pl-k">|</span> <span class="pl-k">|</span> <span class="pl-k">|</span> <span class="pl-k">|</span><span class="pl-k">/</span> <span class="pl-s"><span class="pl-pds"><span class="pl-c1">_</span>`</span> |  |</span>
<span class="pl-s">  | | |_| | | | (_| |  |  Version 0.4.0 (2015-10-08 06:20 UTC)</span>
<span class="pl-s"> _/ |<span class="pl-cce">\_</span>_'_|_|_|<span class="pl-cce">\_</span>_'_|  |  Official http://julialang.org/ release</span>
<span class="pl-s">|__/                   |  x86_64-apple-darwin13.4.0</span>
<span class="pl-s"></span>
<span class="pl-s">julia&gt; versioninfo()</span>
<span class="pl-s">Julia Version 0.4.0</span>
<span class="pl-s">Commit 0ff703b* (2015-10-08 06:20 UTC)</span>
<span class="pl-s">Platform Info:</span>
<span class="pl-s">  System: Darwin (x86_64-apple-darwin13.4.0)</span>
<span class="pl-s">  CPU: Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz</span>
<span class="pl-s">  WORD_SIZE: 64</span>
<span class="pl-s">  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)</span>
<span class="pl-s">  LAPACK: libopenblas64_</span>
<span class="pl-s">  LIBM: libopenlibm</span>
<span class="pl-s">  LLVM: libLLVM-3.3</span>
<span class="pl-s"></span>
<span class="pl-s">julia&gt; using ApproxFun</span>
<span class="pl-s"></span>
<span class="pl-s">julia&gt; x=Fun(identity,[-1.,1.])</span>
<span class="pl-s">Fun([0.0,1.0],Chebyshev(【-1.0,1.0】))</span>
<span class="pl-s"></span>
<span class="pl-s">julia&gt; f=x+sin(2x)*sqrt(1-x^2)</span>
<span class="pl-s"></span>
<span class="pl-s">signal (11): Segmentation fault: 11</span>
<span class="pl-s">jl_method_table_assoc_exact at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:251</span>
<span class="pl-s">jl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1663</span>
<span class="pl-s">maxspace at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Space.jl:230</span>
<span class="pl-s">union at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Space.jl:297</span>
<span class="pl-s">isconvertible at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Space.jl:311</span>
<span class="pl-s">jlcall_isconvertible_22217 at  (unknown line)</span>
<span class="pl-s">jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1691</span>
<span class="pl-s">sumspacecoefficients at /Users/solver/.julia/v0.4/ApproxFun/src/Spaces/Modifier/Modifier.jl:102</span>
<span class="pl-s">coefficients at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Fun.jl:45</span>
<span class="pl-s">call at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/constructors.jl:54</span>
<span class="pl-s">jlcall_call_22211 at  (unknown line)</span>
<span class="pl-s">jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1691</span>
<span class="pl-s">+ at /Users/solver/.julia/v0.4/ApproxFun/src/Fun/Fun.jl:181</span>
<span class="pl-s">jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1691</span>
<span class="pl-s">jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:55</span>
<span class="pl-s">eval at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:213</span>
<span class="pl-s">eval at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:219</span>
<span class="pl-s">eval_body at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:592</span>
<span class="pl-s">jl_toplevel_eval_body at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:527</span>
<span class="pl-s">jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:521</span>
<span class="pl-s">jl_toplevel_eval_in at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/builtins.c:579</span>
<span class="pl-s">eval_user_input at REPL.jl:62</span>
<span class="pl-s">jlcall_eval_user_input_21258 at  (unknown line)</span>
<span class="pl-s">jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1325</span>
<span class="pl-s">anonymous at REPL.jl:92</span>
<span class="pl-s">jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/task.c:241</span>
<span class="pl-s">Segmentation fault: 11<span class="pl-pds">`</span></span>``


</pre></div>
<p dir="auto">I think I might have stumbled across a bug, possibly in type inference though I'm not sure.</p>
<p dir="auto">I'd expect that running the following would print "ok" 3 times, instead it prints "ok" once then two blank lines.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="function printit(x, _)
    if _true()
        z = id(x)
        print(&quot;&quot;)
        println(z)
        :sym
    elseif _false()
        printit(&quot;ok&quot;, :foo)
    end
end

function id(x)
    if _false()
        printit(unknowntype, :foo)
    else
        x
    end
end

_false() = false
_true() = true

printit(&quot;ok&quot;, &quot;foo&quot;)
printit(&quot;ok&quot;, :foo)
printit(&quot;ok&quot;, :foo)"><pre class="notranslate"><code class="notranslate">function printit(x, _)
    if _true()
        z = id(x)
        print("")
        println(z)
        :sym
    elseif _false()
        printit("ok", :foo)
    end
end

function id(x)
    if _false()
        printit(unknowntype, :foo)
    else
        x
    end
end

_false() = false
_true() = true

printit("ok", "foo")
printit("ok", :foo)
printit("ok", :foo)
</code></pre></div>
<p dir="auto">Making any one of the following changes results in the expected output. Perhaps this will help point someone who understands Julia's internals at the cause of the unexpected behavior.</p>
<ol dir="auto">
<li>Remove the <code class="notranslate">printit("ok", "foo")</code> line. (Results in "ok" been printed twice as expected.)</li>
<li>Remove the <code class="notranslate">:sym</code> line.</li>
<li>Remove the <code class="notranslate">print("")</code> line.</li>
<li>Remove either of the <code class="notranslate">if</code> expressions leaving only the non-redundant branch.</li>
<li>Replace <code class="notranslate">unknowntype</code> with <code class="notranslate">unknowntype::ASCIIString</code>.</li>
<li>Remove either of the calls to <code class="notranslate">printit</code> within <code class="notranslate">printit</code> or <code class="notranslate">id</code>.</li>
</ol>
<p dir="auto">I've also just noticed that replacing <code class="notranslate">println(z)</code> with <code class="notranslate">println(z==nothing ? "nothing" : z)</code> causes a seg fault.</p>
<p dir="auto">All of this is happening with the latest nightly build, details below. I get very similar results using v0.3.4, but not the seg fault.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Julia Version 0.4.0-dev+2689
Commit a418672 (2015-01-14 10:05 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM)2 Duo CPU     T7700  @ 2.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Core2)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3"><pre class="notranslate"><code class="notranslate">Julia Version 0.4.0-dev+2689
Commit a418672 (2015-01-14 10:05 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM)2 Duo CPU     T7700  @ 2.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Core2)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
</code></pre></div>