Skip to content
BY 4.0 license Open Access Published by De Gruyter Open Access March 26, 2019

Type errors for the IDE with Xtext and Xsemantics

  • Lorenzo Bettini EMAIL logo
From the journal Open Computer Science


Providing IDE support for a programming language or a DSL (Domain Specific Language) helps the users of the language to be more productive and to have an immediate feedback on possible errors in a program. Static types can drive IDE mechanisms such as the content assist to propose sensible completions in a given program context. Types can also be used to enrich other typical IDE parts such as the Outline and theHovering pop-ups. In this paper, we focus on statically typed imperative languages, adopting some form of type inference. We present a few general patterns for implementing efficient type systems, focusing on type error recovery. This way, the type system is able to type as many parts of the program as possible, keeping a good IDE experience. Type error messages will be placed on the important parts of the program, avoiding cascading errors that can confuse the user. We show two case studies:we apply the presented patterns to implement the type system of two statically typed DSLs, a simple expression language and a reduced Java-like language, with OOP features. We use Xtext as the language workbench for implementing the compiler and the IDE support andXsemantics, a DSL for implementing type systems using a syntax that mimics formal systems. The patterns shown in the paper can be reused also for implementing languages with other language frameworks.


[1] Fowler M., Language Workbenches: The killer-app for domain specific languages?, 2005, in Google Scholar

[2] Bettini L., Implementing domain-specific languages with Xtext and Xtend, Packt Publishing, 2nd ed., 2016Search in Google Scholar

[3] Igarashi A., Pierce B., Wadler P., Featherweight Java: a minimal core calculus for Java and GJ, ACM TOPLAS, 2001, 23(3), 396–45010.1145/503502.503505Search in Google Scholar

[4] Bettini L., Implementing type systems for the IDE with Xsemantics, Journal of Logical and Algebraic Methods in Programming, 2016, 85(5, Part 1), 655–68010.1016/j.jlamp.2015.11.005Search in Google Scholar

[5] Aho A. V., Lam M. S., Sethi R., Ullman J. D. (Eds.), Compilers: principles, techniques, and tools, Addison Wesley, 2nd ed., 2007Search in Google Scholar

[6] Haase A., Völter M., Efftinge S., Kolb B., Introduction to open Architecture Ware 4.1.2, In: MDD Tool Implementers Forum, 2007Search in Google Scholar

[7] Kats L. C. L., Visser E., The Spoofax language workbench, Rules for declarative specification of languages and IDEs, In: OOPSLA, ACM, 2010, 444–46310.1145/1932682.1869497Search in Google Scholar

[8] Hemel Z., Groenewegen D. M., Kats L. C. L., Visser E., Static consistency checking of Web applications with WebDSL, Journal of Symbolic Computation, 2011, 46(2), 150–18210.1016/j.jsc.2010.08.006Search in Google Scholar

[9] Steinberg D., Budinsky F., Paternostro M., Merks E., EMF: Eclipse Modeling Framework, Addison-Wesley, 2nd ed., 2008Search in Google Scholar

[10] Prasanna D. R., Dependency Injection: Design patterns using Spring and Guice, Manning, 1st ed., 2009Search in Google Scholar

[11] Reps T., Teitelbaum T., The synthesizer generator, In: Software Engineering Symposiumon Practical Software Development Environments, ACM, 1984, 42–4810.1145/390010.808247Search in Google Scholar

[12] Sewell P., Nardelli F. Z., Owens S., Peskine G., Ridge T., Sarkar S., Strnisa R., Ott: Effective tool support for the working semanticist, Journal of Functional Programming, 2010, 20(1), 71–12210.1017/S0956796809990293Search in Google Scholar

[13] Ekman T., Hedin G., The JastAdd system – modular extensible compiler construction, Science of Computer Programming, 2007, 69(1-3), 14–2610.1016/j.scico.2007.02.003Search in Google Scholar

[14] Konat G., Kats L., Wachsmuth G., Visser E., Declarative name binding and scope rules, In: SLE, LNCS, Springer, 2012, 7745, 311–33110.1007/978-3-642-36089-3_18Search in Google Scholar

[15] Pierce B. C., Types and Programming Languages, Cambridge, MA: The MIT Press, 2002Search in Google Scholar

[16] Cardelli L., Type systems, ACM Computing Surveys, 1996, 28(1), 263–26410.1145/234313.234418Search in Google Scholar

[17] Hindley J. R., Basic Simple Type Theory, Cambridge University Press, 1987Search in Google Scholar

[18] Visser E., Wachsmuth G., Tolmach A. P., Neron P., Vergu V. A., Passalaqua A., Konat G., A language designer’s workbench: a one-stop-shop for implementation and verification of language designs, In: Onward!, ACM, 2014, 95–11110.1145/2661136.2661149Search in Google Scholar

[19] Vergu V. A., Neron P., Visser E., DynSem: A DSL for dynamic semantics specification, In: RTA, LIPIcs, Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, 2015, 3, 365–378Search in Google Scholar

[20] Efftinge S., Eysholdt M., Köhnlein J., Zarnekow S., Hasselbring W., von Massow R., Xbase: implementing domain-specific languages for Java, In: GPCE, ACM, 2012, 112–12110.1145/2480361.2371419Search in Google Scholar

[21] Gosling J., Joy B., Steele G., Bracha G., Buckley A., The Java language specification, Java SE 7 Edition, Addison-Wesley, 2013Search in Google Scholar

[22] Bettini L., von Pilgrim J., Reiser M.-O., Implementing a typed Java script and its IDE: a case-study with Xsemantics, International Journal on Advances in Software, 2016, 9(3-4), 283–303Search in Google Scholar

[23] Johnson G. F. , Walz J. A., A maximum-flow approach to anomaly isolation in unification-based incremental type inference, In: POPL, ACM, 1986, 44–5710.1145/512644.512649Search in Google Scholar

[24] Wand M., Finding the source of type errors, In: POPL, ACM, 1986, 38–4310.1145/512644.512648Search in Google Scholar

[25] Heeren B., Top Quality Type Error Messages, PhD thesis, Utrecht University, Netherlands, 2005Search in Google Scholar

[26] Lerner B. S., Flower M., Grossman D., Chambers C., Searching for type-error messages, In: PLDI, ACM, 2007, 425–43410.1145/1273442.1250783Search in Google Scholar

[27] Chambers C., Chen S., Le D., Scaffidi C., The function, and dysfunction, of information sources in learning functional programming, Journal of Computing Sciences in Colleges, 2012, 28(1), 220–226Search in Google Scholar

[28] Tirronen V., Uusi-Mäkelä S., Isomöttönen V., Understanding beginners’ mistakes with Haskell, Journal of Functional Programming, 2015, 2510.1017/S0956796815000179Search in Google Scholar

[29] Hudak P., Building domain-specific embedded languages, ACM Computing Surveys, 1996, 28(4es), 19610.1145/242224.242477Search in Google Scholar

[30] Hage J., DOMain Specific Type Error Diagnosis (DOMSTED), Tech. Rep. UU-CS-2014-019, Department of Information and Computing Sciences, Utrecht University, 2014Search in Google Scholar

[31] Heeren B., Hage J., Swierstra S. D., Scripting the type inference process, In: ICFP, ACM, 2003, 3–1310.1145/944746.944707Search in Google Scholar

[32] Stuckey P. J., Sulzmann M., Wazny J., Improving type error diagnosis, In: SIGPLAN Workshop on Haskell, ACM, 2004, 80–9110.1145/1017472.1017486Search in Google Scholar

[33] Wazny J., Type inference and type error diagnosis for Hindley/Milner with extensions, PhD thesis, University of Melbourne, Australia, 2006Search in Google Scholar

[34] Plociniczak H., Miller H., Odersky M., Improving humancompiler interaction through customizable type feedback, Tech. Rep. 197948, EPFL, 2014Search in Google Scholar

[35] Charguéraud A., Improving type error messages in OCaml, In: ML/OCaml, EPTCS, 2014, 198, 80–9710.4204/EPTCS.198.4Search in Google Scholar

[36] Serrano A., Hage J., Type error diagnosis for embedded DSLs by two-stage specialized type rules, In: ESOP, LNCS, Springer, 2016, 9632, 672–69810.1007/978-3-662-49498-1_26Search in Google Scholar

[37] Serrano A., Hage J., Type error customization in GHC: Controlling expression-level type errors by type-level programming, In: IFL, ACM, 2017, 2:1–2:1510.1145/3205368.3205370Search in Google Scholar

[38] Wu B., Chen S., How type errors were fixed and what students did?, In: OOPSLA, ACM, 2017, 1, 105:1–105:2710.1145/3133929Search in Google Scholar

[39] Chen S., Erwig M., Early detection of type errors in C++ templates, In: PEPM, ACM, 2014, 133–14410.1145/2543728.2543731Search in Google Scholar

[40] el Boustani N., Hage J., Improving type error messages for generic Java, Higher-Order and Symbolic Computation, 2011, 24(1), 3–3910.1007/s10990-011-9070-3Search in Google Scholar

[41] Damas L., Milner R., Principal type schemes for functional programs, In: POPL, ACM, 1982, 207–21210.1145/582153.582176Search in Google Scholar

[42] Stuckey P. J., Sulzmann M., Wazny J., Interactive type debugging in Haskell, In: SIGPLAN Workshop on Haskell, ACM, 2003, 72–8310.1145/871895.871903Search in Google Scholar

[43] Haack C., Wells J., Type error slicing in implicitly typed higherorder languages, Science of Computer Programming, 2004, 50(1), 189–22410.1016/j.scico.2004.01.004Search in Google Scholar

[44] Hage J., Heeren B., Heuristics for type error discovery and recovery, In: IFL, LNCS, Springer, 2007, 4449, 199–21610.1007/978-3-540-74130-5_12Search in Google Scholar

[45] el Boustani N., Hage J., Corrective hints for type incorrect generic Java programs, In: PEPM, ACM, 2010, 5–1410.1145/1706356.1706360Search in Google Scholar

[46] Chen S., Erwig M., Counter-factual typing for debugging type errors, In: POPL, ACM, 2014, 583–59410.1145/2578855.2535863Search in Google Scholar

[47] Zhang D., Myers A. C., Vytiniotis D., Jones S. L. P., Diagnosing type errors with class, In: PLDI, ACM, 2015, 12–2110.1145/2813885.2738009Search in Google Scholar

[48] Wu B., Campora III J. P., Chen S., Learning user friendly typeerror messages, In: OOPSLA, ACM, 2017, 1, 106:1–106:2910.1145/3133930Search in Google Scholar

[49] Bruch M., Monperrus M., Mezini M., Learning from examples to improve code completion systems, In: ESEC/SIGSOFT FSE, ACM, 2009, 213–22210.1145/1595696.1595728Search in Google Scholar

[50] Parr T., Vinju J. J., Towards a universal code formatter through machine learning, In: SLE, ACM, 2016, 137–15110.1145/2997364.2997383Search in Google Scholar

[51] Voelter M., Benz S., Dietrich C., Engelmann B., Helander M., Kats L. C. L., Visser E.,Wachsmuth G., DSL Engineering-Designing, Implementing and Using Domain-Specific Languages, 2013Search in Google Scholar

[52] Pfeiffer M., Pichler J., A comparison of tool support for textual domain-specific languages, In: OOPSLA Workshop on Domain Specific Modeling, 2008, 1–7Search in Google Scholar

[53] Erdweg S., van der Storm T., Völter M., Tratt L., Bosman R., Cook W. R., et al., Evaluating and comparing language workbenches: Existing results and benchmarks for the future, Computer Languages, Systems & Structures, 2015, 44(A)10.1016/ in Google Scholar

[54] Charles P., Fuhrer R., Sutton Jr. S., Duesterwald E., Vinju J., Accelerating the creation of customized, language-Specific IDEs in Eclipse, In: OOPSLA, ACM, 2009, 191–20610.1145/1639949.1640104Search in Google Scholar

[55] Jouault F., Bézivin J., Kurtev I., TCS: a DSL for the specification of textual concrete syntaxes in model engineering, In: GPCE, ACM, 2006, 249–25410.1145/1173706.1173744Search in Google Scholar

[56] Heidenreich F., Johannes J., Karol S., Seifert M., Wende C., Derivation and Refinement of Textual Syntax for Models, In: ECMDA-FA, LNCS, Springer, 2009, 5562, 114–12910.1007/978-3-642-02674-4_9Search in Google Scholar

[57] Voelter M., Language and IDE modularization and composition with MPS, In: GTTSE, LNCS, Springer, 2011, 7680, 383–43010.1007/978-3-642-35992-7_11Search in Google Scholar

[58] Bravenboer M., Kalleberg K. T., Vermaas R., Visser E., Stratego/XT 0.17. A language and toolset for program transformation, Science of Computer Programming, 2008, 72(1-2), 52–7010.1016/j.scico.2007.11.003Search in Google Scholar

[59] Van Antwerpen H., Néron P., Tolmach A., Visser E., Wachsmuth G., A constraint language for static semantic analysis based on scope graphs, In: PEPM, ACM, 2016, 49–6010.1145/2847538.2847543Search in Google Scholar

[60] Van Antwerpen H., Bach Poulsen C., Rouvoet A., Visser E., Scopes as types, In: Proceedings of the ACM on Programming Languages, 2018, 2(OOPSLA), 114:1–114:3010.1145/3276484Search in Google Scholar

[61] Vacchi E., Cazzola W., Neverlang: A Framework for Feature-Oriented Language Development, Computer Languages, Systems & Structures, 2015, 43(3), 1–4010.1016/ in Google Scholar

[62] Völter M., Xtext/TS - a type system framework for Xtext, 2011, in Google Scholar

[63] Wyk E. V., Bodin D., Gao J., Krishnan L., Silver: an extensible attribute grammar system, Science of Computer Programming, 2010, 75(1), 39–5410.1016/j.scico.2009.07.004Search in Google Scholar

[64] Bürger C., Karol S., Wende C., Aßmann U., Reference attribute grammars for metamodel semantics, In: SLE, LNCS, Springer, 2011, 6563, 22–4110.1007/978-3-642-19440-5_3Search in Google Scholar

[65] Mernik M., Lenic M., Avdicausevic E., Zumer V., LISA: an interactive environment for programming language development, In: Compiler Construction, LNCS, Springer, 2002, 2304, 1–410.1007/3-540-45937-5_1Search in Google Scholar

[66] Knuth D. E., Semantics of context-free languages,Mathematical Systems Theory, 1968, 2(2), 127–14510.1007/BF01692511Search in Google Scholar

[67] Borras P., Clement D., Despeyroux T., Incerpi J., Kahn G., Lang B., Pascual V., CENTAUR: the system, In: Software Engineering Symposium on Practical Software Development Environments, SIGPLAN, ACM, 1988, 24, 14–2410.1145/64140.65005Search in Google Scholar

[68] Van den Brand M., Heering J., Klint P., Olivier P. A., Compiling language definitions: the ASF+SDF compiler, ACM TOPLAS, 2002, 24(4), 334–36810.1145/567097.567099Search in Google Scholar

[69] Dijkstra A., Swierstra S. D., Ruler: programming type rules, In: FLOPS, LNCS, Springer, 2006, 3945, 30–4610.1007/11737414_4Search in Google Scholar

[70] Felleisen M., Findler R. B., Flatt M., Semantics Engineering with PLT Redex, Cambridge, Mass.: The MIT Press, 2009Search in Google Scholar

[71] Xu H., EriLex: An Embedded Domain Specific Language Generator, In: TOOLS, LNCS, Springer, 2010, 6141, 192–21210.1007/978-3-642-13953-6_11Search in Google Scholar

[72] Bettini L., A DSL for writing type systems for Xtext languages, In: PPPJ, ACM, 2011, 31–4010.1145/2093157.2093163Search in Google Scholar

[73] Bettini L., Stoll D., Völter M., Colameo S., Approaches and tools for implementing type systems in Xtext, In: SLE, LNCS, Springer, 2012, 7745, 392–41210.1007/978-3-642-36089-3_22Search in Google Scholar

[74] Bettini L., Implementing Java-like languages in Xtext with Xsemantics, In: OOPS (SAC), ACM, 2013, 1559–156410.1145/2480362.2480654Search in Google Scholar

[75] Heiduk A., Skatulla S., From Spaghetti to Xsemantics - Practical experiences migrating type systems for 12 languages, XtextCon, 2015Search in Google Scholar

[76] Bettini L., von Pilgrim J., Reiser M.-O., Implementing the Type System for a Typed Javascript and its IDE, In: COMPUTATION TOOLS, IARIA, 2016, 6–11Search in Google Scholar

[77] Igarashi A., Nagira H., Union types for object-oriented programming, Journal of Object Technology, 2007, 6(2), 31–4510.5381/jot.2007.6.2.a3Search in Google Scholar

[78] Cameron N., Ernst E., Drossopoulou S., Towards an Existential Types Model for Java Wildcards, In: Formal Techniques for Javalike Programs (FTfJP), 2007Search in Google Scholar

[79] Yang J., Michaelson G., Trinder P., Wells J. B., Improved Type Error Reporting, In: Workshop on Implementation of Functional Languages, Aachner Informatik-Berichte, 2000, 71–86Search in Google Scholar

Received: 2018-06-29
Accepted: 2019-02-11
Published Online: 2019-03-26

© 2019 Lorenzo Bettini, published by De Gruyter Open

This work is licensed under the Creative Commons Attribution 4.0 Public License.

Downloaded on 11.6.2023 from
Scroll to top button