JuliaLang / julia

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

ERROR: error compiling anonymous: unsupported or misplaced expression export in function anonymous #8051

Closed kmsquire closed 5 years ago

kmsquire commented 10 years ago

I receive the error in the subject when I attempt to conditionally compile the source code below.

However, if I remove ;flip=false from the definition of play, everything compiles and works fine, including the export line.

This seems inconsistent to me, although I'd be happy with an explanation and/or a workaround.

try
    if isa(Main.ImageView, Module)
        # Define read and retrieve for Images
        global playvideo, play
        export playvideo, play

        function play(f; flip=false)
            img = read(f, Main.Images.Image)
            flip && (img = fliplr(img))
            canvas, _ = Main.ImageView.view(img)

            while !eof(f)
                read!(f, img)
                flip && (img = fliplr(img))
                Main.ImageView.view(canvas, img)
                sleep(1/f.framerate)
            end
        end

        function playvideo(video)
            f = VideoIO.openvideo(video)
            play(f)
        end
    end
end

For reference, this is from here.

I'm on a version of master compiled today:

julia> versioninfo()
Julia Version 0.4.0-dev+236
Commit 93d73e7* (2014-08-19 03:23 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
JeffBezanson commented 10 years ago

Very related: #2586 #6195 #5352

There are all kinds of issues with putting top-level expressions in strange places.

kmsquire commented 10 years ago

Thanks, Jeff. I am looking forward to #6195 or some variation thereof. Cheers!

hayd commented 9 years ago

I get this error when trying to do conditionally import Base.Markdown in Markdown.jl:

module Markdown
if VERSION > v"0.4-"
    for f in names(Base.Markdown, true, false)
       eval(Expr(:export, f))
    end
else
# rest of code

Which doesn't quite work without the conditional anyways!

kmsquire commented 5 years ago

Addressed by using Requires. See https://github.com/JuliaLang/julia/issues/2025#issuecomment-338005473 and below for discussion.