@@ -8,8 +8,9 @@ import qualified Data.Map.Strict as Map
88import qualified Data.Maybe as Maybe
99import Data.Text (Text)
1010
11+import qualified AST.Module.Name as ModuleName
1112import AST.Type (Super(..))
12−import qualified AST.Variable as Var
13+import qualified Elm.Name as N
1314import qualified Reporting.Region as R
1415import qualified Reporting.Error.Type as Error
1516import qualified Type.Occurs as Occurs
@@ -130,8 +131,8 @@ detectDecoder :: Variable -> IO Bool
130131detectDecoder variable =
131132 do (Descriptor content _ _ _) <- UF.descriptor variable
132133 case content of
133− Structure (App1 name [_]) | Var.decoder == name ->
134− return True
134+ Structure (App1 home name [_]) ->
135+ return (home == ModuleName.jsonDecode && name == "Decoder")
135136
136137 _ ->
137138 return False
@@ -198,8 +199,8 @@ actuallyUnify context@(Context _ _ (Descriptor firstContent _ _ _) _ (Descriptor
198199 RigidSuper super name ->
199200 unifyRigid context (Just super) name firstContent secondContent
200201
201− Alias name args realVar ->
202− unifyAlias context name args realVar secondContent
202+ Alias home name args realVar ->
203+ unifyAlias context home name args realVar secondContent
203204
204205 Structure flatType ->
205206 unifyStructure context flatType firstContent secondContent
@@ -234,7 +235,7 @@ unifyFlex context otherContent =
234235 RigidSuper _ _ ->
235236 merge context otherContent
236237
237− Alias _ _ _ ->
238+ Alias _ _ _ _ ->
238239 merge context otherContent
239240
240241 Structure _ ->
@@ -272,7 +273,7 @@ unifyRigid context maybeSuper name content otherContent =
272273 mismatch context $ Just $
273274 Error.RigidClash name otherName
274275
275− Alias otherName _ _ ->
276+ Alias _ otherName _ _ ->
276277 mismatch context $ Just $
277278 maybe Error.RigidVarTooGeneric Error.RigidSuperTooGeneric maybeSuper name $
278279 Error.SpecificType otherName
@@ -289,7 +290,7 @@ unifyRigid context maybeSuper name content otherContent =
289290flatTypeToSpecificThing :: FlatType -> Error.SpecificThing
290291flatTypeToSpecificThing flatType =
291292 case flatType of
292− App1 name _ ->
293+ App1 _ name _ ->
293294 Error.SpecificType name
294295
295296 Fun1 _ _ ->
@@ -301,6 +302,12 @@ flatTypeToSpecificThing flatType =
301302 Record1 _ _ ->
302303 Error.SpecificRecord
303304
305+ Unit1 ->
306+ Error.SpecificUnit
307+
308+ Tuple1 _ _ _ ->
309+ Error.SpecificTuple
310+
304311
305312
306313-- UNIFY SUPER VARIABLES
@@ -355,7 +362,7 @@ unifyFlexSuper context super content otherContent =
355362 CompAppend -> merge context content
356363 Number -> mismatch context Nothing -- Error.NumberAppendableClash
357364
358− Alias _ _ realVar ->
365+ Alias _ _ _ realVar ->
359366 subUnify context (_first context) realVar
360367
361368 Error _ ->
@@ -369,32 +376,38 @@ combineRigidSupers rigid flex =
369376 || (rigid == CompAppend && (flex == Comparable || flex == Appendable))
370377
371378
372−atomMatchesSuper :: Super -> Var.Canonical -> Bool
373−atomMatchesSuper super name =
379+atomMatchesSuper :: Super -> ModuleName.Canonical -> N.Name -> Bool
380+atomMatchesSuper super home name =
381+ home == ModuleName.basics
382+ &&
374383 case super of
375384 Number ->
376− elem name [ Var.int, Var.float ]
385+ name == N.int
386+ || name == N.float
377387
378388 Comparable ->
379− elem name [ Var.string, Var.int, Var.float, Var.char]
389+ name == N.int
390+ || name == N.float
391+ || name == N.string
392+ || name == N.char
380393
381394 Appendable ->
382− name == Var.string
395+ name == N.string
383396
384397 CompAppend ->
385− name == Var.string
398+ name == N.string
386399
387400
388401unifyFlexSuperStructure :: Context -> Super -> FlatType -> Unify ()
389402unifyFlexSuperStructure context super flatType =
390403 case flatType of
391− App1 name [] ->
392− if atomMatchesSuper super name then
404+ App1 home name [] ->
405+ if atomMatchesSuper super home name then
393406 merge context (Structure flatType)
394407 else
395408 mismatch context $ Just $ Error.NotPartOfSuper super
396409
397− App1 name [variable] | name == Var.list ->
410+ App1 home name [variable] | home == ModuleName.list && name == N.list ->
398411 case super of
399412 Number ->
400413 mismatch context $ Just $ Error.NotPartOfSuper super
@@ -412,7 +425,7 @@ unifyFlexSuperStructure context super flatType =
412425 merge context (Structure flatType)
413426 unifyComparableRecursive (_orientation context) variable
414427
415− App1 name args | Var.isTuple name ->
428+ Tuple1 a b cs ->
416429 case super of
417430 Number ->
418431 mismatch context $ Just $ Error.NotPartOfSuper super
@@ -421,13 +434,9 @@ unifyFlexSuperStructure context super flatType =
421434 mismatch context $ Just $ Error.NotPartOfSuper super
422435
423436 Comparable ->
424− if length args > 6 then
425− mismatch context (Just (Error.TooLongComparableTuple (length args)))
426−
427− else
428− do comparableOccursCheck context
429− merge context (Structure flatType)
430− mapM_ (unifyComparableRecursive (_orientation context)) args
437+ do comparableOccursCheck context
438+ merge context (Structure flatType)
439+ mapM_ (unifyComparableRecursive (_orientation context)) (a:b:cs)
431440
432441 CompAppend ->
433442 mismatch context $ Just $ Error.NotPartOfSuper super
@@ -461,11 +470,11 @@ unifyComparableRecursive orientation var =
461470-- UNIFY ALIASES
462471
463472
464−unifyAlias :: Context -> Var.Canonical -> [(Text, Variable)] -> Variable -> Content -> Unify ()
465−unifyAlias context name args realVar otherContent =
473+unifyAlias :: Context -> ModuleName.Canonical -> N.Name -> [(Text, Variable)] -> Variable -> Content -> Unify ()
474+unifyAlias context home name args realVar otherContent =
466475 case otherContent of
467476 FlexVar _ ->
468− merge context (Alias name args realVar)
477+ merge context (Alias home name args realVar)
469478
470479 FlexSuper _ _ ->
471480 subUnify context realVar (_second context)
@@ -476,8 +485,8 @@ unifyAlias context name args realVar otherContent =
476485 RigidSuper _ _ ->
477486 subUnify context realVar (_second context)
478487
479− Alias otherName otherArgs otherRealVar ->
480− if name == otherName then
488+ Alias otherHome otherName otherArgs otherRealVar ->
489+ if name == otherName && home == otherHome then
481490 do zipWithM_ (subUnify context) (map snd args) (map snd otherArgs)
482491 merge context otherContent
483492
@@ -510,17 +519,17 @@ unifyStructure context flatType content otherContent =
510519 RigidSuper super name ->
511520 mismatch context $ Just $ Error.RigidSuperTooGeneric super name (flatTypeToSpecificThing flatType)
512521
513− Alias _ _ realVar ->
522+ Alias _ _ _ realVar ->
514523 subUnify context (_first context) realVar
515524
516525 Structure otherTerm ->
517526 case (flatType, otherTerm) of
518− (App1 name args, App1 otherName otherArgs) ->
519− if name == otherName then
527+ (App1 home name args, App1 otherHome otherName otherArgs) ->
528+ if home == otherHome && name == otherName then
520529 do zipWithM_ (subUnify context) args otherArgs
521530 merge context otherContent
522531
523− else if isIntFloat name otherName || isIntFloat otherName name then
532+ else if isIntFloat home name otherHome otherName then
524533 mismatch context (Just Error.IntFloat)
525534
526535 else
@@ -553,9 +562,15 @@ unifyStructure context flatType content otherContent =
553562
554563
555564
556−isIntFloat :: Var.Canonical -> Var.Canonical -> Bool
557−isIntFloat name otherName =
558− Var.isPrim "Int" name && Var.isPrim "Float" otherName
565+isIntFloat :: ModuleName.Canonical -> N.Name -> ModuleName.Canonical -> N.Name -> Bool
566+isIntFloat home name otherHome otherName =
567+ otherHome == ModuleName.basics
568+ && home == ModuleName.basics
569+ && (
570+ (name == N.int && otherName == N.float)
571+ ||
572+ (name == N.float && otherName == N.int)
573+ )
559574
560575
561576
@@ -668,7 +683,7 @@ gatherFields context fields variable =
668683 Structure EmptyRecord1 ->
669684 return (RecordStructure fields variable Empty)
670685
671− Alias _ _ var ->
686+ Alias _ _ _ var ->
672687 -- TODO may be dropping useful alias info here
673688 gatherFields context fields var
674689