<p dir="auto">There is a weird compile behaviour that should not happen. Consider the function:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@inline function num_unique(group_str::AbstractString)
    return group_str |&gt; Set |&gt; length
end"><pre class="notranslate"><span class="pl-c1">@inline</span> <span class="pl-k">function</span> <span class="pl-en">num_unique</span>(group_str<span class="pl-k">::</span><span class="pl-c1">AbstractString</span>)
    <span class="pl-k">return</span> group_str <span class="pl-k">|&gt;</span> Set <span class="pl-k">|&gt;</span> length
<span class="pl-k">end</span></pre></div>
<p dir="auto">That is used in a super function (with two variants and their output and lowered code). Variant 1:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function sum_unique1(group_strs::Vector{&lt;:AbstractString})
    # clump groups to one line before adding to set (removes the need for union)
    f = x -&gt; replace(x, &quot;\n&quot; =&gt; &quot;&quot;)
    return group_strs .|&gt; f .|&gt; num_unique |&gt; sum
end"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">sum_unique1</span>(group_strs<span class="pl-k">::</span><span class="pl-c1">Vector{&lt;:AbstractString}</span>)
    <span class="pl-c"><span class="pl-c">#</span> clump groups to one line before adding to set (removes the need for union)</span>
    f <span class="pl-k">=</span> x <span class="pl-k">-&gt;</span> <span class="pl-c1">replace</span>(x, <span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n</span><span class="pl-pds">"</span></span> <span class="pl-k">=&gt;</span> <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>)
    <span class="pl-k">return</span> group_strs <span class="pl-k">.|</span><span class="pl-k">&gt;</span> f <span class="pl-k">.|</span><span class="pl-k">&gt;</span> num_unique <span class="pl-k">|&gt;</span> sum
<span class="pl-k">end</span></pre></div>
<p dir="auto">Output of variant 1 with some string vector as input:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="sum_unique1(group_strs) = 6703"><pre class="notranslate"><code class="notranslate">sum_unique1(group_strs) = 6703
</code></pre></div>
<p dir="auto">Lowered code for variant 1:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@code_lowered sum_unique1([&quot;abaz\nasd&quot;, &quot;ashds\ndshgs&quot;])
CodeInfo(
1 ─      #23 = %new(Main.:(var&quot;#23#24&quot;))
│        f = #23
│   %3 = Base.broadcasted(Main.:|&gt;, group_strs, f)
│   %4 = Base.broadcasted(Main.:|&gt;, %3, Main.num_unique)
│   %5 = Base.materialize(%4)
│   %6 = %5 |&gt; Main.sum
└──      return %6
)"><pre class="notranslate"><span class="pl-c1">@code_lowered</span> <span class="pl-c1">sum_unique1</span>([<span class="pl-s"><span class="pl-pds">"</span>abaz<span class="pl-cce">\n</span>asd<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>ashds<span class="pl-cce">\n</span>dshgs<span class="pl-pds">"</span></span>])
<span class="pl-c1">CodeInfo</span>(
<span class="pl-c1">1</span> ─      <span class="pl-c"><span class="pl-c">#</span>23 = %new(Main.:(var"#23#24"))</span>
│        f <span class="pl-k">=</span> <span class="pl-c"><span class="pl-c">#</span>23</span>
│   <span class="pl-k">%</span><span class="pl-c1">3</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">broadcasted</span>(Main.:<span class="pl-k">|&gt;</span>, group_strs, f)
│   <span class="pl-k">%</span><span class="pl-c1">4</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">broadcasted</span>(Main.:<span class="pl-k">|&gt;</span>, <span class="pl-k">%</span><span class="pl-c1">3</span>, Main<span class="pl-k">.</span>num_unique)
│   <span class="pl-k">%</span><span class="pl-c1">5</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">materialize</span>(<span class="pl-k">%</span><span class="pl-c1">4</span>)
│   <span class="pl-k">%</span><span class="pl-c1">6</span> <span class="pl-k">=</span> <span class="pl-k">%</span><span class="pl-c1">5</span> <span class="pl-k">|&gt;</span> Main<span class="pl-k">.</span>sum
└──      <span class="pl-k">return</span> <span class="pl-k">%</span><span class="pl-c1">6</span>
)</pre></div>
<p dir="auto">Now the okay-looking variant 2:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function sum_unique2(group_strs::Vector{&lt;:AbstractString})
    # clump groups to one line before adding to set (removes the need for union)
    return group_strs .|&gt; x -&gt; replace(x, &quot;\n&quot; =&gt; &quot;&quot;) .|&gt; num_unique |&gt; sum
end"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">sum_unique2</span>(group_strs<span class="pl-k">::</span><span class="pl-c1">Vector{&lt;:AbstractString}</span>)
    <span class="pl-c"><span class="pl-c">#</span> clump groups to one line before adding to set (removes the need for union)</span>
    <span class="pl-k">return</span> group_strs <span class="pl-k">.|</span><span class="pl-k">&gt;</span> x <span class="pl-k">-&gt;</span> <span class="pl-c1">replace</span>(x, <span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n</span><span class="pl-pds">"</span></span> <span class="pl-k">=&gt;</span> <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>) <span class="pl-k">.|</span><span class="pl-k">&gt;</span> num_unique <span class="pl-k">|&gt;</span> sum
<span class="pl-k">end</span></pre></div>
<p dir="auto">Output of variant 2:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="sum_unique2(group_strs) = [3, 16, 22, 22, ...] # is the output array where sum(output array) = 6703"><pre class="notranslate"><code class="notranslate">sum_unique2(group_strs) = [3, 16, 22, 22, ...] # is the output array where sum(output array) = 6703
</code></pre></div>
<p dir="auto">Lowered code of variant 2:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@code_lowered sum_unique2([&quot;abaz\nasd&quot;, &quot;ashds\ndshgs&quot;])
CodeInfo(
1 ─      #27 = %new(Main.:(var&quot;#27#28&quot;))
│   %2 = #27
│   %3 = Base.broadcasted(Main.:|&gt;, group_strs, %2)
│   %4 = Base.materialize(%3)
└──      return %4 # doesn't even call sum and just exits!
)"><pre class="notranslate"><span class="pl-c1">@code_lowered</span> <span class="pl-c1">sum_unique2</span>([<span class="pl-s"><span class="pl-pds">"</span>abaz<span class="pl-cce">\n</span>asd<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>ashds<span class="pl-cce">\n</span>dshgs<span class="pl-pds">"</span></span>])
<span class="pl-c1">CodeInfo</span>(
<span class="pl-c1">1</span> ─      <span class="pl-c"><span class="pl-c">#</span>27 = %new(Main.:(var"#27#28"))</span>
│   <span class="pl-k">%</span><span class="pl-c1">2</span> <span class="pl-k">=</span> <span class="pl-c"><span class="pl-c">#</span>27</span>
│   <span class="pl-k">%</span><span class="pl-c1">3</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">broadcasted</span>(Main.:<span class="pl-k">|&gt;</span>, group_strs, <span class="pl-k">%</span><span class="pl-c1">2</span>)
│   <span class="pl-k">%</span><span class="pl-c1">4</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">materialize</span>(<span class="pl-k">%</span><span class="pl-c1">3</span>)
└──      <span class="pl-k">return</span> <span class="pl-k">%</span><span class="pl-c1">4</span> <span class="pl-c"><span class="pl-c">#</span> doesn't even call sum and just exits!</span>
)</pre></div>
<p dir="auto">This lowered code can be reproduced for the following function:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function sum_unique(group_strs::Vector{&lt;:AbstractString})
   return group_strs .|&gt; (x -&gt; replace(x, &quot;\n&quot; =&gt; &quot;&quot;) .|&gt; num_unique |&gt; sum)
end"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">sum_unique</span>(group_strs<span class="pl-k">::</span><span class="pl-c1">Vector{&lt;:AbstractString}</span>)
   <span class="pl-k">return</span> group_strs <span class="pl-k">.|</span><span class="pl-k">&gt;</span> (x <span class="pl-k">-&gt;</span> <span class="pl-c1">replace</span>(x, <span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n</span><span class="pl-pds">"</span></span> <span class="pl-k">=&gt;</span> <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>) <span class="pl-k">.|</span><span class="pl-k">&gt;</span> num_unique <span class="pl-k">|&gt;</span> sum)
<span class="pl-k">end</span></pre></div>
<p dir="auto">Lowered code which is identical to the above "flawed" variant <code class="notranslate">sum_unique2()</code>:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@code_lowered sum_unique([&quot;abaz\nasd&quot;, &quot;ashds\ndshgs&quot;])
CodeInfo(
1 ─      #11 = %new(Main.:(var&quot;#11#12&quot;))
│   %2 = #11
│   %3 = Base.broadcasted(Main.:|&gt;, group_strs, %2)
│   %4 = Base.materialize(%3)
└──      return %4
)"><pre class="notranslate"><span class="pl-c1">@code_lowered</span> <span class="pl-c1">sum_unique</span>([<span class="pl-s"><span class="pl-pds">"</span>abaz<span class="pl-cce">\n</span>asd<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>ashds<span class="pl-cce">\n</span>dshgs<span class="pl-pds">"</span></span>])
<span class="pl-c1">CodeInfo</span>(
<span class="pl-c1">1</span> ─      <span class="pl-c"><span class="pl-c">#</span>11 = %new(Main.:(var"#11#12"))</span>
│   <span class="pl-k">%</span><span class="pl-c1">2</span> <span class="pl-k">=</span> <span class="pl-c"><span class="pl-c">#</span>11</span>
│   <span class="pl-k">%</span><span class="pl-c1">3</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">broadcasted</span>(Main.:<span class="pl-k">|&gt;</span>, group_strs, <span class="pl-k">%</span><span class="pl-c1">2</span>)
│   <span class="pl-k">%</span><span class="pl-c1">4</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">materialize</span>(<span class="pl-k">%</span><span class="pl-c1">3</span>)
└──      <span class="pl-k">return</span> <span class="pl-k">%</span><span class="pl-c1">4</span>
)</pre></div>
<p dir="auto">Therefore the <code class="notranslate">sum</code> here was hidden inside the anonymous function and the output didn't change because of summing over a scalar. Also, interestingly, this problem goes away if chaining is done inside broadcasted function <code class="notranslate">num_unique</code> like below:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@inline function num_unique(group_str::AbstractString)
    # clump groups to one line before adding to set (removes the need for union)
    return group_str |&gt; x -&gt; replace(x, &quot;\n&quot; =&gt; &quot;&quot;) |&gt; Set |&gt; length
end"><pre class="notranslate"><span class="pl-c1">@inline</span> <span class="pl-k">function</span> <span class="pl-en">num_unique</span>(group_str<span class="pl-k">::</span><span class="pl-c1">AbstractString</span>)
    <span class="pl-c"><span class="pl-c">#</span> clump groups to one line before adding to set (removes the need for union)</span>
    <span class="pl-k">return</span> group_str <span class="pl-k">|&gt;</span> x <span class="pl-k">-&gt;</span> <span class="pl-c1">replace</span>(x, <span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n</span><span class="pl-pds">"</span></span> <span class="pl-k">=&gt;</span> <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>) <span class="pl-k">|&gt;</span> Set <span class="pl-k">|&gt;</span> length
<span class="pl-k">end</span></pre></div>
<p dir="auto">And just wrapping the anonymous function in parenthesis also does the trick (of solving this issue):</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function sum_unique(group_strs::Vector{&lt;:AbstractString})
    # clump groups to one line before adding to set (removes the need for union)
    return group_strs .|&gt; (x -&gt; replace(x, &quot;\n&quot; =&gt; &quot;&quot;)) .|&gt; num_unique |&gt; sum
end"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">sum_unique</span>(group_strs<span class="pl-k">::</span><span class="pl-c1">Vector{&lt;:AbstractString}</span>)
    <span class="pl-c"><span class="pl-c">#</span> clump groups to one line before adding to set (removes the need for union)</span>
    <span class="pl-k">return</span> group_strs <span class="pl-k">.|</span><span class="pl-k">&gt;</span> (x <span class="pl-k">-&gt;</span> <span class="pl-c1">replace</span>(x, <span class="pl-s"><span class="pl-pds">"</span><span class="pl-cce">\n</span><span class="pl-pds">"</span></span> <span class="pl-k">=&gt;</span> <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>)) <span class="pl-k">.|</span><span class="pl-k">&gt;</span> num_unique <span class="pl-k">|&gt;</span> sum
<span class="pl-k">end</span></pre></div>
<p dir="auto">But these ways of getting around this problem essentially express the same code (or should!). It will be great if this can be investigated a bit more. I am very new to Julia, so I haven't been able to go deeper (yet).</p>
<p dir="auto">My Julia version info is below:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Julia Version 1.5.2
Commit 539f3ce943 (2020-09-23 23:17 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, ivybridge)
Environment:
  JULIA_EDITOR = &quot;/snap/code/51/usr/share/code/code&quot;
  JULIA_NUM_THREADS = "><pre class="notranslate">Julia Version <span class="pl-c1">1.5</span>.<span class="pl-c1">2</span>
Commit <span class="pl-c1">539f3</span>ce943 (<span class="pl-c1">2020</span><span class="pl-k">-</span><span class="pl-c1">09</span><span class="pl-k">-</span><span class="pl-c1">23</span> <span class="pl-c1">23</span><span class="pl-k">:</span><span class="pl-c1">17</span> UTC)
Platform Info<span class="pl-k">:</span>
  OS<span class="pl-k">:</span> Linux (x86_64<span class="pl-k">-</span>pc<span class="pl-k">-</span>linux<span class="pl-k">-</span>gnu)
  CPU<span class="pl-k">:</span> <span class="pl-c1">Intel</span>(R) <span class="pl-c1">Core</span>(TM) i7<span class="pl-k">-</span><span class="pl-c1">3630</span>QM CPU @ <span class="pl-c1">2.40</span>GHz
  WORD_SIZE<span class="pl-k">:</span> <span class="pl-c1">64</span>
  LIBM<span class="pl-k">:</span> libopenlibm
  LLVM<span class="pl-k">:</span> libLLVM<span class="pl-k">-</span><span class="pl-c1">9.0</span>.<span class="pl-c1">1</span> (ORCJIT, ivybridge)
Environment<span class="pl-k">:</span>
  JULIA_EDITOR <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span>/snap/code/51/usr/share/code/code<span class="pl-pds">"</span></span>
  JULIA_NUM_THREADS <span class="pl-k">=</span> </pre></div>
<h1 dir="auto">Issue</h1>
<p dir="auto">Doing</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="data .|&gt; x -&gt; f(x, 2) .|&gt; g"><pre class="notranslate">data <span class="pl-k">.|</span><span class="pl-k">&gt;</span> x <span class="pl-k">-&gt;</span> <span class="pl-c1">f</span>(x, <span class="pl-c1">2</span>) <span class="pl-k">.|</span><span class="pl-k">&gt;</span> g</pre></div>
<p dir="auto">expands to</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="data .|&gt; x -&gt; (f(x,2) .|&gt; g)"><pre class="notranslate">data <span class="pl-k">.|</span><span class="pl-k">&gt;</span> x <span class="pl-k">-&gt;</span> (<span class="pl-c1">f</span>(x,<span class="pl-c1">2</span>) <span class="pl-k">.|</span><span class="pl-k">&gt;</span> g)</pre></div>
<p dir="auto">but should expand to</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="data .|&gt; (x -&gt; f(x,2)) .|&gt; g"><pre class="notranslate">data <span class="pl-k">.|</span><span class="pl-k">&gt;</span> (x <span class="pl-k">-&gt;</span> <span class="pl-c1">f</span>(x,<span class="pl-c1">2</span>)) <span class="pl-k">.|</span><span class="pl-k">&gt;</span> g</pre></div>
<h1 dir="auto">Workaround</h1>
<p dir="auto">Add parentheses</p>