{"id":16964999,"url":"https://github.com/propensive/larceny","last_synced_at":"2025-10-10T20:41:50.712Z","repository":{"id":127467881,"uuid":"607849228","full_name":"propensive/larceny","owner":"propensive","description":"Scala 3 compiler plugin for testing compiler errors","archived":false,"fork":false,"pushed_at":"2025-01-23T19:42:12.000Z","size":2996,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T20:41:49.382Z","etag":null,"topics":["compilation-errors","compile-time","compiler-plugin","scala","testing"],"latest_commit_sha":null,"homepage":"https://soundness.dev/larceny/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/propensive.png","metadata":{"files":{"readme":".github/readme.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-28T19:56:53.000Z","updated_at":"2025-01-23T19:42:16.000Z","dependencies_parsed_at":"2023-11-16T09:26:01.809Z","dependency_job_id":"39cd490d-189f-41bd-8952-de4a0d730c8c","html_url":"https://github.com/propensive/larceny","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/propensive/larceny","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Flarceny","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Flarceny/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Flarceny/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Flarceny/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/propensive","download_url":"https://codeload.github.com/propensive/larceny/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Flarceny/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005275,"owners_count":26083863,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compilation-errors","compile-time","compiler-plugin","scala","testing"],"created_at":"2024-10-13T23:44:48.519Z","updated_at":"2025-10-10T20:41:50.694Z","avatar_url":"https://github.com/propensive.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[\u003cimg alt=\"GitHub Workflow\" src=\"https://img.shields.io/github/actions/workflow/status/propensive/larceny/main.yml?style=for-the-badge\" height=\"24\"\u003e](https://github.com/propensive/larceny/actions)\n[\u003cimg src=\"https://img.shields.io/discord/633198088311537684?color=8899f7\u0026label=DISCORD\u0026style=for-the-badge\" height=\"24\"\u003e](https://discord.com/invite/MBUrkTgMnA)\n\u003cimg src=\"/doc/images/github.png\" valign=\"middle\"\u003e\n\n# Larceny\n\n__Scala 3 compiler plugin for testing compiletime errors__\n\nUnlike runtime errors, compilation errors prevent successful compilation, which\nmakes them harder to test, since we can't even compile the units tests we want\nto write and run to test them!\n\n__Larceny__ makes it possible to write those tests. Code which would normally\nfail compilation, for any reason (provided it parses as well-formed Scala) is\npermitted inside certain blocks of code, but instead of being compiled and run,\ninstead returns a list of compilation errors, as runtime values, which are\nperfect for testing.\n\n## Features\n\n- suppresses compilation errors on ordinary code blocks\n- code must at least parse, but all errors will be lifted to runtime values\n- allows compilation errors to be tested in unit testing frameworks\n- unit tests on compilation errors can be written in the most natural way\n\n\n## Availability\n\n\n\n\n\n\n\n## Getting Started\n\nLarceny is a compiler plugin, and can be included in a compilation with the\n`-Xplugin:larceny.jar` parameter to `scalac`:\n```sh\nscalac -d bin -Xplugin:larceny.jar -classpath larceny.jar *.scala\n```\n\nThe compiler plugin identifies code blocks whose compilation errors should be\nsuppressed, which are inside a `demilitarize` block (using any\nvalid Scala syntax), for example:\n```scala\npackage com.example\n\nimport larceny.*\n\n@main def run(): Unit =\n  demilitarize(\"Hello world\".substring(\"5\"))\n\n  demilitarize:\n    val x = 8\n    println(x.missingMethod)\n```\n\nHere, the code inside each `demilitarize` block will never compile:\nthe first, because `substring` takes an `Int` as a parameter, and the second\nbecause `missingMethod` is not a member of `Int`.\n\nBut despite this, if the Larceny plugin is enabled, then the code will compile.\n\nAny invalid code that is _not_ within a `demilitarize` block will\nstill result in the expected compilation errors.\n\nThe compilation error from each `demilitarize` block will be\nreturned (in a `List`) from each block. We could adjust the code to see them,\nlike so:\n```scala\n@main def run(): Unit =\n  val errors = demilitarize:\n    \"Hello world\".substring(\"5\")\n\n  errors.foreach:\n    case CompileError(ordinal, message, code, position, offset) =\u003e\n      println(s\"[$id] Found error '$message' in the code '$code' with offset $offset\")\n```\n\nThe parameters of `CompileError` need some explanation:\n- `ordinal` is the ordinal identifier representing the type of error; the Scala\n  compiler defines about 200 such error types (though some occur more\n  frequently than others)\n- `message` is the human-readable error message text that would be output by\n  the compiler\n- `code` is the fragment of code which would be marked as problematic (in an\n  IDE, this would usually be done with a wavy red underline)\n- `position` is the location of the code from the start of the source file\n- `offset` is the number of characters from the start of `code` that is\n  marked as the exact point of the error\n\nTaking the second example above,\n```scala\ndemilitarize:\n  val x = 8\n  println(x.missingMethod)\n```\nthe `message` would be:\n```\nvalue missingMethod is not a member of Int\n```\nwhile the `code` value would be `x.missingMethod` (note that the surrounding\n`println` is not considered erroneous), and the `offset` would be `2`. The\nvalue `2` is because the erroneous code begins `x.`, but the point of the error\nis considered to be the `m` of `missingMethod`, which is character `2`.\n\nThe error IDs are defined in the Scala compiler and correspond to an\nenumeration of values. For convenience, these values have been copied into the\n`CompileErrorId` enumeration, and can be accessed by the `id` method of\n`CompileError`.\n\n`CompileErrorId` is also an extractor on `CompileError`, so it's possible to\nwrite:\n```scala\ndemilitarize(summon[Ordering[Exception]]) match\n  case ErrorId(ErrorId.MissingImplicitArgumentID) =\u003e \"expected\"\n  case _                                          =\u003e \"unexpected\"\n```\n\n### Implementation\n\nHere are the details of how Larceny works. It should not be necessary to\nunderstand its implementation for normal usage, but as experimental software,\nit may behave unexpectedly, and this explanation may help to diagnose\nmisbehavior.\n\nLarceny runs on each source file before typechecking, but after parsing. Any\nblocks named `demilitarize` found in the the untyped AST will trigger\na new and independent compilation of the same source file (with the same\nclasspath, but without the Larceny plugin) from _within_ the main compilation.\n\nSince the `demilitarize` blocks should contain compile errors, this\nchild compilation is expected to fail, but its compilation errors will be\ncaptured. Each compilation error which is positioned within a\n`demilitarize` block will be converted to static code which constructs\na new `CompileError` instance, and inserts it into the `demilitarize`\nblock, in place of entire erroneous contents.\n\nIf there are multiple `demilitarize` blocks in the same source file,\nsome errors which occur in earlier phases of compilation may suppress later\nphases from running, and the errors from those later phases will not be\ncaptured during the first compilation. Larceny will rerun the compiler as\nmany times as necessary to capture errors from later phases, each time\nremoving more code which would have precluded these later phases.\n\nThe main compilation is then allowed to continue to typechecking, which will\nonly see the `CompileError` constructions, not the original code. As long as\nthere are no compilation errors _outside_ of a `demilitarize` block,\ncompilation should succeed. When the code is run, each `demilitarize`\nblock will simply return a list of `CompileError`s.\n\n### Testing Frameworks\n\nLarceny should work with any Scala unit testing framework or library. For\nexample, with [Probably](https://github.com/propensive/probably/), we could\nwrite a compile error test with:\n```scala\ntest(t\"cannot sort data without an Ordering\"):\n  demilitarize(data.sorted).head.message\n.assert(_.startsWith(\"No implicit Ordering\"))\n```\n\n\n## Status\n\nLarceny is classified as __maturescent__. For reference, Soundness projects are\ncategorized into one of the following five stability levels:\n\n- _embryonic_: for experimental or demonstrative purposes only, without any guarantees of longevity\n- _fledgling_: of proven utility, seeking contributions, but liable to significant redesigns\n- _maturescent_: major design decisions broady settled, seeking probatory adoption and refinement\n- _dependable_: production-ready, subject to controlled ongoing maintenance and enhancement; tagged as version `1.0.0` or later\n- _adamantine_: proven, reliable and production-ready, with no further breaking changes ever anticipated\n\nProjects at any stability level, even _embryonic_ projects, can still be used,\nas long as caution is taken to avoid a mismatch between the project's stability\nlevel and the required stability and maintainability of your own project.\n\nLarceny is designed to be _small_. Its entire source code currently consists\nof 346 lines of code.\n\n## Building\n\nLarceny will ultimately be built by Fury, when it is published. In the\nmeantime, two possibilities are offered, however they are acknowledged to be\nfragile, inadequately tested, and unsuitable for anything more than\nexperimentation. They are provided only for the necessity of providing _some_\nanswer to the question, \"how can I try Larceny?\".\n\n1. *Copy the sources into your own project*\n   \n   Read the `fury` file in the repository root to understand Larceny's build\n   structure, dependencies and source location; the file format should be short\n   and quite intuitive. Copy the sources into a source directory in your own\n   project, then repeat (recursively) for each of the dependencies.\n\n   The sources are compiled against the latest nightly release of Scala 3.\n   There should be no problem to compile the project together with all of its\n   dependencies in a single compilation.\n\n2. *Build with [Wrath](https://github.com/propensive/wrath/)*\n\n   Wrath is a bootstrapping script for building Larceny and other projects in\n   the absence of a fully-featured build tool. It is designed to read the `fury`\n   file in the project directory, and produce a collection of JAR files which can\n   be added to a classpath, by compiling the project and all of its dependencies,\n   including the Scala compiler itself.\n   \n   Download the latest version of\n   [`wrath`](https://github.com/propensive/wrath/releases/latest), make it\n   executable, and add it to your path, for example by copying it to\n   `/usr/local/bin/`.\n\n   Clone this repository inside an empty directory, so that the build can\n   safely make clones of repositories it depends on as _peers_ of `larceny`.\n   Run `wrath -F` in the repository root. This will download and compile the\n   latest version of Scala, as well as all of Larceny's dependencies.\n\n   If the build was successful, the compiled JAR files can be found in the\n   `.wrath/dist` directory.\n\n## Contributing\n\nContributors to Larceny are welcome and encouraged. New contributors may like\nto look for issues marked\n[beginner](https://github.com/propensive/larceny/labels/beginner).\n\nWe suggest that all contributors read the [Contributing\nGuide](/contributing.md) to make the process of contributing to Larceny\neasier.\n\nPlease __do not__ contact project maintainers privately with questions unless\nthere is a good reason to keep them private. While it can be tempting to\nrepsond to such questions, private answers cannot be shared with a wider\naudience, and it can result in duplication of effort.\n\n## Author\n\nLarceny was designed and developed by Jon Pretty, and commercial support and\ntraining on all aspects of Scala 3 is available from [Propensive\nO\u0026Uuml;](https://propensive.com/).\n\n\n\n## Name\n\nLarceny is the act of unlawfully taking something from someone. _Larceny_ unlawfully takes errors from compiletime and gives them to runtime.\n\nIn general, Soundness project names are always chosen with some rationale,\nhowever it is usually frivolous. Each name is chosen for more for its\n_uniqueness_ and _intrigue_ than its concision or catchiness, and there is no\nbias towards names with positive or \"nice\" meanings—since many of the libraries\nperform some quite unpleasant tasks.\n\nNames should be English words, though many are obscure or archaic, and it\nshould be noted how willingly English adopts foreign words. Names are generally\nof Greek or Latin origin, and have often arrived in English via a romance\nlanguage.\n\n## Logo\n\nThe logo shows a shape of a medieval fortification, alluding to a \"demilitarized zone\" akin to the `demilitarized` scopes Larceny provides.\n\n## License\n\nLarceny is copyright \u0026copy; 2025 Jon Pretty \u0026 Propensive O\u0026Uuml;, and\nis made available under the [Apache 2.0 License](/license.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Flarceny","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpropensive%2Flarceny","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Flarceny/lists"}