@@ -69,6 +69,9 @@ data Error
6969 | ModuleNameMismatch ModuleName. Raw (A. Located ModuleName. Raw )
7070 | UnexpectedPort A. Region
7171 | NoPorts A. Region
72+ | NoPortsInPackage (A. Located Name. Name )
73+ | NoPortModulesInPackage A. Region
74+ | NoEffectsOutsideKernel A. Region
7275 | ParseError Module
7376
7477
@@ -561,10 +564,84 @@ toReport source err =
561564 ]
562565 )
563566
567+ NoPortsInPackage (A. At region _) ->
568+ Report. Report " PACKAGES CANNOT HAVE PORTS" region [] $
569+ Code. toSnippet source region Nothing
570+ (
571+ D. reflow $
572+ " Packages cannot declare any ports, so I am getting stuck here:"
573+ ,
574+ D. stack
575+ [ D. reflow $
576+ " Remove this port declaration."
577+ , noteForPortsInPackage
578+ ]
579+ )
580+
581+ NoPortModulesInPackage region ->
582+ Report. Report " PACKAGES CANNOT HAVE PORTS" region [] $
583+ Code. toSnippet source region Nothing
584+ (
585+ D. reflow $
586+ " Packages cannot declare any ports, so I am getting stuck here:"
587+ ,
588+ D. stack
589+ [ D. fillSep $
590+ [" Remove" ," the" ,D. cyan " port" ," keyword" ," and" ," I"
591+ ," should" ," be" ," able" ," to" ," continue."
592+ ]
593+ , noteForPortsInPackage
594+ ]
595+ )
596+
597+ NoEffectsOutsideKernel region ->
598+ Report. Report " INVALID EFFECT MODULE" region [] $
599+ Code. toSnippet source region Nothing
600+ (
601+ D. reflow $
602+ " It is not possible to declare an `effect module` outside the @elm organization,\
603+ \ so I am getting stuck here:"
604+ ,
605+ D. stack
606+ [ D. reflow $
607+ " Switch to a normal module declaration."
608+ , D. toSimpleNote $
609+ " Effect modules are designed to allow certain core functionality to be\
610+ \ defined separately from the compiler. So the @elm organization has access to\
611+ \ this so that certain changes, extensions, and fixes can be introduced without\
612+ \ needing to release new Elm binaries. For example, we want to make it possible\
613+ \ to test effects, but this may require changes to the design of effect modules.\
614+ \ By only having them defined in the @elm organization, that kind of design work\
615+ \ can proceed much more smoothly."
616+ ]
617+ )
618+
564619 ParseError modul ->
565620 toParseErrorReport source modul
566621
567622
623+ noteForPortsInPackage :: D. Doc
624+ noteForPortsInPackage =
625+ D. stack
626+ [ D. toSimpleNote $
627+ " One of the major goals of the package ecosystem is to be completely written\
628+ \ in Elm. This means when you install an Elm package, you can be sure you are safe\
629+ \ from security issues (like code that runs side-effects on install) and that you\
630+ \ are not going to get any runtime exceptions coming from your new dependency.\
631+ \ This design also sets the Elm ecosystem up well to target other platforms (like\
632+ \ mobile phones, WebAssembly, etc.) since no community code explicitly depends on\
633+ \ JavaScript even existing."
634+ , D. reflow $
635+ " Given that overall goal, allowing ports in packages would lead to some pretty\
636+ \ surprising behavior. If ports were allowed in packages, you could install a\
637+ \ package but not realize that it brings in an indirect dependency that defines a\
638+ \ port. Now you have a program that does not work and the fix is to realize that\
639+ \ some JavaScript needs to be added. That would be extremely frustrating! So why\
640+ \ not allow the package author to include the necessary JS code as well? Now we\
641+ \ are back in conflict with our goals for the ecosystem overall."
642+ ]
643+
644+
568645toParseErrorReport :: Code. Source -> Module -> Report. Report
569646toParseErrorReport source modul =
570647 case modul of
0 commit comments