CurricularAnalytics / CurricularAnalytics.jl

CurricularAnalytics.jl is a toolbox for studying and analyzing academic program curricula.
GNU Affero General Public License v3.0
23 stars 19 forks source link

DegreePlan() constructor - Warning: Method definition overwritten #112

Open haydenfree opened 3 years ago

haydenfree commented 3 years ago

Dreaded warning:

WARNING: Method definition (::Type{CurricularAnalytics.DegreePlan})(AbstractString, CurricularAnalytics.Curriculum, Array{CurricularAnalytics.Term, 1}) in module CurricularAnalytics at /Users/hayden/.julia/packages/CurricularAnalytics/qqlQU/src/DataTypes/DegreePlan.jl:74 overwritten at /Users/hayden/.julia/packages/CurricularAnalytics/qqlQU/src/DataTypes/DegreePlan.jl:99.
  ** incremental compilation may be fatally broken for this module **

Below is an explanation of why. Fix needs to be implemented.

# assert type check, so check if 1+2 yields abstractfloat (does not)
julia> (1+2)::AbstractFloat
ERROR: TypeError: in typeassert, expected AbstractFloat, got a value of type Int64
Stacktrace:
 [1] top-level scope at REPL[3]:1

# yields an Int, of which number is a supertype, so it does yield a number
julia> (1+2)::Number
3

# A is a Course
julia> A = Course("A", 3, institution="ACME State", prefix="BW", num="101", canonical_name="Baskets I")
Course(2159971713, Dict{Int64,Int64}(), "A", 3, "BW", "101", "ACME State", "", "", Course[], "Baskets I", Dict{Int64,Requisite}(), LearningOutcome[], Dict{String,Any}(), Dict{String,Any}(), 0.5)

julia> supertypes(Course)
(Course, CurricularAnalytics.AbstractCourse, Any)

# A is an AbstractCourse since that's a supertype of Course
julia> (A)::CurricularAnalytics.AbstractCourse
Course(2159971713, Dict{Int64,Int64}(), "A", 3, "BW", "101", "ACME State", "", "", Course[], "Baskets I", Dict{Int64,Requisite}(), LearningOutcome[], Dict{String,Any}(), Dict{String,Any}(), 0.5)

# Create array with just A
julia> arr = [A]
1-element Array{Course,1}:
 Course(2159971713, Dict{Int64,Int64}(), "A", 3, "BW", "101", "ACME State", "", "", Course[], "Baskets I", Dict{Int64,Requisite}(), LearningOutcome[], Dict{String,Any}(), Dict{String,Any}(), 0.5)

# Array{Course,1} is not an Array of AbstractCourses.
julia> arr::Array{CurricularAnalytics.AbstractCourse,1}
ERROR: TypeError: in typeassert, expected Array{CurricularAnalytics.AbstractCourse,1}, got a value of type Array{Course,1}
Stacktrace:
 [1] top-level scope at REPL[19]:1

# However, using syntax Array{<:Integer} refers to all arrays whose element type is some kind of Integer

# Array{Course,1} is an array whose element is some type of AbstractCourse
julia> arr::Array{<:CurricularAnalytics.AbstractCourse,1}
1-element Array{Course,1}:
 Course(2159971713, Dict{Int64,Int64}(), "A", 3, "BW", "101", "ACME State", "", "", Course[], "Baskets I", Dict{Int64,Requisite}(), LearningOutcome[], Dict{String,Any}(), Dict{String,Any}(), 0.5)

# for sanity, show that an array of Int64 is not an array whose elements are some type of AbstractCourse.
julia> nums = [1,2,3]
3-element Array{Int64,1}:
 1
 2
 3

julia> nums::Array{<:CurricularAnalytics.AbstractCourse,1}
ERROR: TypeError: in typeassert, expected Array{var"#s3",1} where var"#s3"<:CurricularAnalytics.AbstractCourse, got a value of type Array{Int64,1}
Stacktrace:
 [1] top-level scope at REPL[22]:1
heileman commented 3 years ago

Incredibly helpful - and it wins you a "Bridge prize." Fixed this warning in commit: https://github.com/CurricularAnalytics/CurricularAnalytics.jl/commit/3cbe92c58fb7337d7bc9054b579d2244154cddc2