From 1ddf7f0ce207169e336e54ec3dfae1bc59ddb156 Mon Sep 17 00:00:00 2001 From: ZacNugent Date: Tue, 28 Apr 2020 15:03:38 +0100 Subject: [PATCH] piracy fix --- src/linting/checks.jl | 2 +- test/runtests.jl | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/linting/checks.jl b/src/linting/checks.jl index d0335b30..e2a98a40 100644 --- a/src/linting/checks.jl +++ b/src/linting/checks.jl @@ -507,7 +507,7 @@ end function refers_to_nonimported_type(arg::EXPR) if hasref(arg) && refof(arg) isa Binding return true - elseif typof(arg) === CSTParser.UnaryOpCall && length(arg) == 2 && kindof(arg[1]) === CSTParser.Tokens.DECLARATION + elseif typof(arg) === CSTParser.UnaryOpCall && length(arg) == 2 && (kindof(arg[1]) === CSTParser.Tokens.DECLARATION || kindof(arg[1]) === CSTParser.Tokens.ISSUBTYPE) return refers_to_nonimported_type(arg[2]) elseif _binary_assert(arg, CSTParser.Tokens.DECLARATION) return refers_to_nonimported_type(arg[3]) diff --git a/test/runtests.jl b/test/runtests.jl index e113addd..c1c219bc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -464,6 +464,23 @@ end StaticLint.check_for_pirates(cst[2]) @test errorof(cst[2]) === nothing end + let cst = parse_and_pass(""" + import Base:sin + abstract type T end + sin(x::Array{T}) = 1 + sin(x::Array{<:T}) = 1 + sin(x::Array{Number}) = 1 + sin(x::Array{<:Number}) = 1 + """) + StaticLint.check_for_pirates(cst[3]) + StaticLint.check_for_pirates(cst[4]) + StaticLint.check_for_pirates(cst[5]) + StaticLint.check_for_pirates(cst[6]) + @test errorof(cst[3]) === nothing + @test errorof(cst[4]) === nothing + @test errorof(cst[5]) === StaticLint.TypePiracy + @test errorof(cst[6]) === StaticLint.TypePiracy + end end @testset "docs for undescribed variables" begin