Skip to content

Instantly share code, notes, and snippets.

@thautwarm
Last active October 29, 2018 13:14
Show Gist options
  • Save thautwarm/b5fcf3c7bae24b37c4c49227efd71391 to your computer and use it in GitHub Desktop.
Save thautwarm/b5fcf3c7bae24b37c4c49227efd71391 to your computer and use it in GitHub Desktop.

no macro leads to success:

struct A end
struct B end
function f()
enum1 = A()
enum2 = B()
begin
    let enum_test = enum1
        begin
            begin
                let case_test = let
                            begin
                                if (isa)(enum_test, A)
                                    begin
                                        println("A")
                                        enum1 !== A()
                                    end
                                else
                                    MLStyle.Match.Failed()
                                end
                            end
                        end
                    if case_test === MLStyle.Match.Failed()
                        begin
                            throw((MLStyle.Err.InternalException)("Non-exhaustive pattern found!"))
                        end
                    else
                        case_test
                    end
                end
            end
        end
    end
end
end

f()

while

using MLStyle
import MLStyle.MatchExt: enum_next
import Base: (<), (<=)

struct A end
struct B end

show_generated(code) = begin
   code = string(code)
   println(code)
   code = replace(code, r"\s+\#.*?\#\n" => "\n")
   code = replace(code, "@case.test@" => "case_test")
   replace(code, "@:enum1.1@" => "enum_test") |> println
end

function f()

    enum1 = A()
    enum2 = B()

    show_generated(macroexpand(AAA, :(
    @match enum1 begin
        ::A =>
            begin
                println("A")
                enum2 !== A()
            end
    end
    ), recursive=false))

    @match enum1 begin
        ::A =>
            begin
                println("A")
                enum2 !== A()
            end

    end
end

f()

ERROR: LoadError: MLStyle.Err.InternalException("Non-exhaustive pattern found!")

leads to

begin
    #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:179 =#
    let @:enum1.1@ = enum1
        #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:180 =#
        begin
            #= C:\Users\v-wazhao\github\MLStyle.jl\temp\a.jl:50 =#
            begin
                #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:161 =#
                let @case.test@ = let
                            #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:163 =#
                            begin
                                #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:112 =#
                                if (isa)(@:enum1.1@, A)
                                    #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:113 =#
                                    begin
                                        #= C:\Users\v-wazhao\github\MLStyle.jl\temp\a.jl:52 =#
                                        println("A")
                                        #= C:\Users\v-wazhao\github\MLStyle.jl\temp\a.jl:53 =#
                                        enum2 !== A()
                                    end
                                else
                                    #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:115 =#
                                    MLStyle.Match.Failed()
                                end
                            end
                        end
                    #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:165 =#
                    if @case.test@ === MLStyle.Match.Failed()
                        #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:166 =#
                        begin
                            #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:149 =#
                            throw((MLStyle.Err.InternalException)("Non-exhaustive pattern found!"))
                        end
                    else
                        #= C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:168 =#
                        @case.test@
                    end
                end
            end
        end
    end
end
begin
    let enum_test = enum1
        begin
            begin
                let case_test = let
                            begin
                                if (isa)(enum_test, A)
                                    begin
                                        println("A")
                                        enum2 !== A()
                                    end
                                else
                                    MLStyle.Match.Failed()
                                end
                            end
                        end
                    if case_test === MLStyle.Match.Failed()
                        begin
                            throw((MLStyle.Err.InternalException)("Non-exhaustive pattern found!"))
                        end
                    else
                        case_test
                    end
                end
            end
        end
    end
end
A
ERROR: LoadError: MLStyle.Err.InternalException("Non-exhaustive pattern found!")
Stacktrace:
 [1] f() at C:\Users\v-wazhao\github\MLStyle.jl\src\Match.jl:165
 [2] top-level scope at none:0
 [3] include at .\boot.jl:317 [inlined]
 [4] include_relative(::Module, ::String) at .\loading.jl:1041
 [5] include(::Module, ::String) at .\sysimg.jl:29
 [6] include(::String) at .\client.jl:388
 [7] top-level scope at none:0
in expression starting at C:\Users\v-wazhao\github\MLStyle.jl\temp\a.jl:68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment