blob: e4454afc1146cb2826a5177223da488edfdeb6f9 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 1.5.5">
<meta name="author" content="2019-08-08 13:15:33 CEST">
<title>N4JS Language Specification</title>
<link rel="stylesheet" href="styles/spec.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<!-- ************* docinfo ******************************************************************* -->
<!-- ************* Favicon ************-->
<link rel="icon" href="images/favicon.ico" />
<!-- ************* Back-to-top JQuery ************* -->
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<link href="styles/prism.min.css" rel="stylesheet" />
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<!-- ************* Styles ************* -->
<link rel="stylesheet" type="text/css" href="styles/n4jsspec-adoc.css">
<!-- ****************** NavBar ****************** -->
<div id="menubar">
<div class="banner">
<a href="https://www.eclipse.org/n4js/#"><img id="logo" src="images/n4js-logo.png" alt="Eclipse N4JS"></a>
</div>
<ul>
<li><a href="index.html">Index</a></li>
</ul>
</div>
<!-- ************* docinfo ******************************************************************* -->
<style>
.admonitionblock td.icon .icon-todo:before{content:"\f249";color:#f4ee42}
</style>
</head>
<body class="book toc2 toc-left">
<div id="header">
<h1>N4JS Language Specification</h1>
<div class="details">
<span id="author" class="author">2019-08-08 13:15:33 CEST</span><br>
<span id="revnumber">version 0.9</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#_introduction">1. Introduction</a>
<ul class="sectlevel2">
<li><a href="#_notation">1.1. Notation</a>
<ul class="sectlevel3">
<li><a href="#_grammar-notation">1.1.1. Grammar Notation</a></li>
<li><a href="#_type-judgments-and-rules-and-constraints-notation">1.1.2. Type Judgments and Rules and Constraints Notation</a>
<ul class="sectlevel4">
<li><a href="#_typing-rules-and-judgments">1.1.2.1. Typing Rules and Judgments</a></li>
<li><a href="#_types-of-an-element">1.1.2.2. Types of an Element</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_auxiliary-functions">1.2. Auxiliary Functions</a>
<ul class="sectlevel3">
<li><a href="#_binding">1.2.1. Binding</a></li>
<li><a href="#_merging-types">1.2.2. Merging Types</a>
<ul class="sectlevel4">
<li><a href="#_logic-formulas">1.2.2.1. Logic Formulas</a></li>
</ul>
</li>
<li><a href="#_symbols-and-font-convention">1.2.3. Symbols and Font Convention</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_grammar">2. Grammar</a>
<ul class="sectlevel2">
<li><a href="#_lexical-conventions">2.1. Lexical Conventions</a>
<ul class="sectlevel3">
<li><a href="#_identifier-names-and-identifiers">2.1.1. Identifier Names and Identifiers</a></li>
<li><a href="#_this-keyword">2.1.2. This Keyword</a></li>
<li><a href="#_regular-expression-literals">2.1.3. Regular Expression Literals</a></li>
<li><a href="#_automatic-semicolon-insertion">2.1.4. Automatic Semicolon Insertion</a></li>
<li><a href="#_jsdoc">2.1.5. JSDoc</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_names">3. Names</a>
<ul class="sectlevel2">
<li><a href="#_access-control">3.1. Access Control</a></li>
<li><a href="#_accessibility-of-types-top-level-variables-and-function-declarations">3.2. Accessibility of Types, Top-Level Variables and Function Declarations</a>
<ul class="sectlevel3">
<li><a href="#_accessibility-of-members">3.2.1. Accessibility of Members</a></li>
<li><a href="#_valid-names">3.2.2. Valid Names</a></li>
<li><a href="#_qualified-names">3.2.3. Qualified Names</a></li>
<li><a href="#_name-duplicates">3.2.4. Name Duplicates</a>
<ul class="sectlevel4">
<li><a href="#_lexical-environment">3.2.4.1. Lexical Environment</a></li>
<li><a href="#_duplicates-and-shadowing">3.2.4.2. Duplicates and Shadowing</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#_types">4. Types</a>
<ul class="sectlevel2">
<li><a href="#_overview">4.1. Overview</a></li>
<li><a href="#_type-expressions">4.2. Type Expressions</a>
<ul class="sectlevel3">
<li><a href="#_syntax">4.2.1. Syntax</a></li>
<li><a href="#_properties">4.2.2. Properties</a></li>
<li><a href="#_semantics">4.2.3. Semantics</a></li>
</ul>
</li>
<li><a href="#_type-inference">4.3. Type Inference</a></li>
<li><a href="#_generic-and-parameterized-types">4.4. Generic and Parameterized Types</a>
<ul class="sectlevel3">
<li><a href="#_generic-types">4.4.1. Generic Types</a></li>
<li><a href="#_type-variables">4.4.2. Type Variables</a></li>
<li><a href="#_parameterized-types">4.4.3. Parameterized Types</a></li>
</ul>
</li>
<li><a href="#_primitive-ecmascript-types">4.5. Primitive ECMAScript Types</a>
<ul class="sectlevel3">
<li><a href="#_undefined-type">4.5.1. Undefined Type</a></li>
<li><a href="#_null-type">4.5.2. Null Type</a></li>
<li><a href="#_primitive-boolean-type">4.5.3. Primitive Boolean Type</a></li>
<li><a href="#_primitive-string-type">4.5.4. Primitive String Type</a></li>
<li><a href="#_primitive-number-type">4.5.5. Primitive Number Type</a></li>
<li><a href="#_primitive-type-int">4.5.6. Primitive Type int</a></li>
<li><a href="#_primitive-symbol-type">4.5.7. Primitive Symbol Type</a></li>
</ul>
</li>
<li><a href="#_primitive-n4js-types">4.6. Primitive N4JS Types</a>
<ul class="sectlevel3">
<li><a href="#_any-type">4.6.1. Any Type</a>
<ul class="sectlevel4">
<li><a href="#any-type-semantics">4.6.1.1. Semantics</a></li>
<li><a href="#any-type-type-inference">4.6.1.2. Type Inference</a>
<ul class="sectlevel5">
<li><a href="#_default-type-of-variables">4.6.1.2.1. Default Type of Variables</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_void-type">4.6.2. Void Type</a>
<ul class="sectlevel4">
<li><a href="#void-type-semantics">4.6.2.1. Semantics</a></li>
</ul>
</li>
<li><a href="#_unknown-type">4.6.3. Unknown Type</a></li>
<li><a href="#_primitive-pathselector-and-i18nkey">4.6.4. Primitive Pathselector and I18nKey</a>
<ul class="sectlevel4">
<li><a href="#pathselector-semantics">4.6.4.1. Semantics</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_built-in-ecmascript-object-types">4.7. Built-in ECMAScript Object Types</a>
<ul class="sectlevel3">
<li><a href="#ECMAScript-objects-semantics">4.7.1. Semantics</a></li>
<li><a href="#_object-type">4.7.2. Object Type</a></li>
<li><a href="#_function-object-type">4.7.3. Function-Object-Type</a></li>
<li><a href="#_array-object-type">4.7.4. Array Object Type</a></li>
<li><a href="#_string-object-type">4.7.5. String Object Type</a></li>
<li><a href="#_boolean-object-type">4.7.6. Boolean Object Type</a></li>
<li><a href="#_number-object-type">4.7.7. Number Object Type</a></li>
<li><a href="#_global-object-type">4.7.8. Global Object Type</a></li>
<li><a href="#_symbol">4.7.9. Symbol</a></li>
<li><a href="#_promise">4.7.10. Promise</a></li>
<li><a href="#_iterator-interface">4.7.11. Iterator Interface</a></li>
<li><a href="#_iterable-interface">4.7.12. Iterable Interface</a></li>
</ul>
</li>
<li><a href="#_built-in-n4js-types">4.8. Built-In N4JS Types</a>
<ul class="sectlevel3">
<li><a href="#_n4object">4.8.1. N4Object</a>
<ul class="sectlevel4">
<li><a href="#N4Object-semantics">4.8.1.1. Semantics</a></li>
</ul>
</li>
<li><a href="#_n4class">4.8.2. N4Class</a></li>
<li><a href="#IterableN">4.8.3. IterableN</a></li>
</ul>
</li>
<li><a href="#_type-modifiers">4.9. Type Modifiers</a>
<ul class="sectlevel3">
<li><a href="#Type_Modifiers_Dynamic">4.9.1. Dynamic</a></li>
<li><a href="#_optional-return-types">4.9.2. Optional Return Types</a></li>
</ul>
</li>
<li><a href="#_union-and-intersection-type-composed-types">4.10. Union and Intersection Type (Composed Types)</a>
<ul class="sectlevel3">
<li><a href="#_union-type">4.10.1. Union Type</a>
<ul class="sectlevel4">
<li><a href="#union-type-syntax">4.10.1.1. Syntax</a></li>
<li><a href="#union-type-semantics">4.10.1.2. Semantics</a></li>
<li><a href="#_warnings">4.10.1.3. Warnings</a></li>
</ul>
</li>
<li><a href="#_intersection-type">4.10.2. Intersection Type</a>
<ul class="sectlevel4">
<li><a href="#intersection-type-syntax">4.10.2.1. Syntax</a></li>
<li><a href="#intersection-type-semantics">4.10.2.2. Semantics</a></li>
<li><a href="#_warnings-2">4.10.2.3. Warnings</a></li>
</ul>
</li>
<li><a href="#_composed-types-in-wildcards">4.10.3. Composed Types in Wildcards</a></li>
<li><a href="#_property-access-for-composed-types">4.10.4. Property Access for Composed Types</a>
<ul class="sectlevel4">
<li><a href="#_properties-of-union-type">4.10.4.1. Properties of Union Type</a>
<ul class="sectlevel5">
<li><a href="#_remarks-on-union-type-s-members">4.10.4.1.1. Remarks on union type’s members:</a></li>
</ul>
</li>
<li><a href="#_properties-of-intersection-type">4.10.4.2. Properties of Intersection Type</a>
<ul class="sectlevel5">
<li><a href="#_remarks-on-intersection-type-s-methods">4.10.4.2.1. Remarks on intersection type’s methods:</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#_constructor-and-classifier-type">4.11. Constructor and Classifier Type</a>
<ul class="sectlevel3">
<li><a href="#_syntax-3">4.11.1. Syntax</a></li>
<li><a href="#_semantics-2">4.11.2. Semantics</a></li>
<li><a href="#_constructors-and-prototypes-in-ecmascript-2015">4.11.3. Constructors and Prototypes in ECMAScript 2015</a></li>
</ul>
</li>
<li><a href="#_this-type">4.12. This Type</a>
<ul class="sectlevel3">
<li><a href="#this-type-syntax">4.12.1. Syntax</a></li>
<li><a href="#this-keyword-semantics">4.12.2. Semantics</a></li>
</ul>
</li>
<li><a href="#_enums">4.13. Enums</a>
<ul class="sectlevel3">
<li><a href="#_enums-n4js">4.13.1. Enums (N4JS)</a>
<ul class="sectlevel4">
<li><a href="#enums-syntax">4.13.1.1. Syntax</a></li>
<li><a href="#enums-semantics">4.13.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="#_string-based-enums">4.13.2. String-Based Enums</a></li>
</ul>
</li>
<li><a href="#_short-hand-syntax">4.14. Short-Hand Syntax</a>
<ul class="sectlevel3">
<li><a href="#_array-short-hand-syntax">4.14.1. Array Short-Hand Syntax</a></li>
<li><a href="#_iterablen-short-hand-syntax">4.14.2. IterableN Short-Hand Syntax</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_classifiers">5. Classifiers</a>
<ul class="sectlevel2">
<li><a href="#_n4js-specific-classifiers">5.1. N4JS Specific Classifiers</a>
<ul class="sectlevel3">
<li><a href="#_properties-2">5.1.1. Properties</a></li>
<li><a href="#_common-semantics-of-classifiers">5.1.2. Common Semantics of Classifiers</a></li>
<li><a href="#_classes">5.1.3. Classes</a>
<ul class="sectlevel4">
<li><a href="#_definition-of-classes">5.1.3.1. Definition of Classes</a>
<ul class="sectlevel5">
<li><a href="#class-syntax">5.1.3.1.1. Syntax</a></li>
<li><a href="#class-properties">5.1.3.1.2. Properties</a></li>
<li><a href="#class-type-inference">5.1.3.1.3. Type Inference</a></li>
</ul>
</li>
<li><a href="#class-semantics">5.1.3.2. Semantics</a></li>
<li><a href="#_final-modifier">5.1.3.3. Final Modifier</a></li>
<li><a href="#_abstract-classes">5.1.3.4. Abstract Classes</a></li>
<li><a href="#_non-instantiable-classes">5.1.3.5. Non-Instantiable Classes</a></li>
<li><a href="#_superclass">5.1.3.6. Superclass</a></li>
</ul>
</li>
<li><a href="#_interfaces">5.1.4. Interfaces</a>
<ul class="sectlevel4">
<li><a href="#_definition-of-interfaces">5.1.4.1. Definition of Interfaces</a>
<ul class="sectlevel5">
<li><a href="#interfaces-syntax">5.1.4.1.1. Syntax</a></li>
<li><a href="#interfaces-properties">5.1.4.1.2. Properties</a></li>
<li><a href="#interfaces-type-inference">5.1.4.1.3. Type Inference</a></li>
<li><a href="#interfaces-semantics">5.1.4.1.4. Semantics</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_generic-classifiers">5.1.5. Generic Classifiers</a></li>
<li><a href="#sec:definition-site-variance">5.1.6. Definition-Site Variance</a></li>
</ul>
</li>
<li><a href="#_members">5.2. Members</a>
<ul class="sectlevel3">
<li><a href="#_syntax-4">5.2.1. Syntax</a>
<ul class="sectlevel4">
<li><a href="#_properties-3">5.2.1.1. Properties</a></li>
</ul>
</li>
<li><a href="#_semantics-3">5.2.2. Semantics</a></li>
<li><a href="#_methods">5.2.3. Methods</a>
<ul class="sectlevel4">
<li><a href="#_syntax-5">5.2.3.1. Syntax</a></li>
<li><a href="#_properties-4">5.2.3.2. Properties</a></li>
<li><a href="#_semantics-4">5.2.3.3. Semantics</a></li>
<li><a href="#_final-methods">5.2.3.4. Final Methods</a></li>
<li><a href="#_abstract-methods">5.2.3.5. Abstract Methods</a></li>
<li><a href="#_generic-methods">5.2.3.6. Generic Methods</a></li>
</ul>
</li>
<li><a href="#_default-methods-in-interfaces">5.2.4. Default Methods in Interfaces</a>
<ul class="sectlevel4">
<li><a href="#_asynchronous-methods">5.2.4.1. Asynchronous Methods</a></li>
</ul>
</li>
<li><a href="#_constructors">5.2.5. Constructors</a>
<ul class="sectlevel4">
<li><a href="#_structural-this-type-in-constructor">5.2.5.1. Structural This Type in Constructor</a></li>
<li><a href="#spec-constructor">5.2.5.2. @Spec Constructor</a></li>
<li><a href="#_callable-constructors">5.2.5.3. Callable Constructors</a></li>
<li><a href="#_covariant-constructors">5.2.5.4. Covariant Constructors</a></li>
</ul>
</li>
<li><a href="#_data-fields">5.2.6. Data Fields</a>
<ul class="sectlevel4">
<li><a href="#data-fields-syntax">5.2.6.1. Syntax</a></li>
<li><a href="#data-fields-properties">5.2.6.2. Properties</a>
<ul class="sectlevel5">
<li><a href="#data-fields-semantics">5.2.6.2.1. Semantics</a></li>
<li><a href="#data-fields-type-inference">5.2.6.2.2. Type Inference</a></li>
</ul>
</li>
<li><a href="#_assignment-modifiers">5.2.6.3. Assignment Modifiers</a></li>
<li><a href="#_field-accessors-getter-setter">5.2.6.4. Field Accessors (Getter/Setter)</a>
<ul class="sectlevel5">
<li><a href="#field-acessors-syntax">5.2.6.4.1. Syntax</a></li>
<li><a href="#field-acessors-properties">5.2.6.4.2. Properties</a></li>
<li><a href="#field-accessors-semantics">5.2.6.4.3. Semantics</a></li>
</ul>
</li>
<li><a href="#optional-fields">5.2.6.5. Optional Fields</a>
<ul class="sectlevel5">
<li><a href="#_syntax-6">5.2.6.5.1. Syntax</a></li>
<li><a href="#_semantics-5">5.2.6.5.2. Semantics</a></li>
<li><a href="#_background">5.2.6.5.3. Background</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_static-members">5.2.7. Static Members</a>
<ul class="sectlevel4">
<li><a href="#_access-from-and-to-static-members">5.2.7.1. Access From and To Static Members</a></li>
<li><a href="#_generic-static-methods">5.2.7.2. Generic static methods</a></li>
<li><a href="#_static-members-of-interfaces">5.2.7.3. Static Members of Interfaces</a></li>
</ul>
</li>
<li><a href="#_redefinition-of-members">5.2.8. Redefinition of Members</a>
<ul class="sectlevel4">
<li><a href="#_overriding-of-members">5.2.8.1. Overriding of Members</a></li>
<li><a href="#_implementation-of-members">5.2.8.2. Implementation of Members</a>
<ul class="sectlevel5">
<li><a href="#_member-consumption">5.2.8.2.1. Member Consumption</a></li>
<li><a href="#_member-implementation">5.2.8.2.2. Member Implementation</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#_structural-typing">5.3. Structural Typing</a>
<ul class="sectlevel3">
<li><a href="#_syntax-7">5.3.1. Syntax</a></li>
<li><a href="#_definition-site-structural-typing">5.3.2. Definition Site Structural Typing</a></li>
<li><a href="#_use-site-structural-typing">5.3.3. Use-Site Structural Typing</a></li>
<li><a href="#structural-readWriteInit-field-typing">5.3.4. Structural Read-only, Write-only and Initializer Field Typing</a></li>
<li><a href="#_public-setter-annotated-with-code-providesinitializer-code">5.3.5. Public Setter Annotated With <code>ProvidesInitializer</code></a></li>
<li><a href="#_structural-types-with-optional-fields">5.3.6. Structural Types With Optional Fields</a></li>
<li><a href="#_structural-types-with-access-modifier">5.3.7. Structural Types With Access Modifier</a></li>
<li><a href="#_structural-types-with-additional-members">5.3.8. Structural Types With Additional Members</a>
<ul class="sectlevel4">
<li><a href="#_syntax-8">5.3.8.1. Syntax</a>
<ul class="sectlevel5">
<li><a href="#_semantics-6">5.3.8.1.1. Semantics</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#_functions">6. Functions</a>
<ul class="sectlevel2">
<li><a href="#_function-type">6.1. Function Type</a>
<ul class="sectlevel3">
<li><a href="#_properties-5">6.1.1. Properties</a></li>
<li><a href="#function-type-inference">6.1.2. Type Inference</a></li>
<li><a href="#_autoboxing-of-function-type">6.1.3. Autoboxing of Function Type</a></li>
<li><a href="#_arguments-object">6.1.4. Arguments Object</a></li>
</ul>
</li>
<li><a href="#_ecmascript-5-function-definition">6.2. ECMAScript 5 Function Definition</a>
<ul class="sectlevel3">
<li><a href="#_function-declaration">6.2.1. Function Declaration</a>
<ul class="sectlevel4">
<li><a href="#_syntax-9">6.2.1.1. Syntax</a></li>
<li><a href="#_semantics-8">6.2.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="#_function-expression">6.2.2. Function Expression</a>
<ul class="sectlevel4">
<li><a href="#function-expression-syntax">6.2.2.1. Syntax</a></li>
<li><a href="#_semantics-and-type-inference">6.2.2.2. Semantics and Type Inference</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_ecmascript-2015-function-definition">6.3. ECMAScript 2015 Function Definition</a>
<ul class="sectlevel3">
<li><a href="#_formal-parameters">6.3.1. Formal Parameters</a>
<ul class="sectlevel4">
<li><a href="#Type_Modifiers_Optional">6.3.1.1. Optional Parameters</a></li>
<li><a href="#Type_Modifiers_Default">6.3.1.2. Default Parameters</a></li>
<li><a href="#Type_Modifiers_Variadic">6.3.1.3. Variadic</a></li>
</ul>
</li>
<li><a href="#_generator-functions">6.3.2. Generator Functions</a>
<ul class="sectlevel4">
<li><a href="#generator-functions-syntax">6.3.2.1. Syntax</a></li>
<li><a href="#generator-functions-semantics">6.3.2.2. Semantics</a></li>
<li><a href="#_generator-arrow-functions">6.3.2.3. Generator Arrow Functions</a></li>
</ul>
</li>
<li><a href="#_arrow-function-expression">6.3.3. Arrow Function Expression</a>
<ul class="sectlevel4">
<li><a href="#arrow-function-expression-syntax">6.3.3.1. Syntax</a></li>
<li><a href="#arrow-function-expression-semantics-and-type-inference">6.3.3.2. Semantics and Type Inference</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_ecmascript-proposals-function-definition">6.4. ECMAScript Proposals Function Definition</a>
<ul class="sectlevel3">
<li><a href="#_asynchronous-functions">6.4.1. Asynchronous Functions</a>
<ul class="sectlevel4">
<li><a href="#asynchronous-functions-syntax">6.4.1.1. Syntax</a></li>
<li><a href="#asynchronous-functions-semantics">6.4.1.2. Semantics</a></li>
<li><a href="#_asynchronous-arrow-functions">6.4.1.3. Asynchronous Arrow Functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_n4js-extended-function-definition">6.5. N4JS Extended Function Definition</a>
<ul class="sectlevel3">
<li><a href="#_generic-functions">6.5.1. Generic Functions</a></li>
<li><a href="#_promisifiable-functions">6.5.2. Promisifiable Functions</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_conversions-and-reflection">7. Conversions and Reflection</a>
<ul class="sectlevel2">
<li><a href="#_autoboxing-and-coercing">7.1. Autoboxing and Coercing</a>
<ul class="sectlevel3">
<li><a href="#_coercing">7.1.1. Coercing</a></li>
<li><a href="#_autoboxing-of-primitives">7.1.2. Autoboxing of Primitives</a></li>
<li><a href="#_autoboxing-of-function-expressions-and-declarations">7.1.3. Autoboxing of Function Expressions and Declarations</a></li>
</ul>
</li>
<li><a href="#_auto-conversion-of-objects">7.2. Auto-Conversion of Objects</a>
<ul class="sectlevel3">
<li><a href="#_auto-conversion-of-class-instances">7.2.1. Auto-Conversion of Class Instances</a>
<ul class="sectlevel4">
<li><a href="#_auto-conversion-of-interface-instances">7.2.1.1. Auto-Conversion of Interface Instances</a></li>
</ul>
</li>
<li><a href="#_auto-conversion-of-enum-literals">7.2.2. Auto-Conversion of Enum Literals</a></li>
</ul>
</li>
<li><a href="#_type-cast-and-type-check">7.3. Type Cast and Type Check</a>
<ul class="sectlevel3">
<li><a href="#_type-cast">7.3.1. Type Cast</a></li>
<li><a href="#_type-check">7.3.2. Type Check</a></li>
</ul>
</li>
<li><a href="#_reflection-meta-information">7.4. Reflection meta-information</a>
<ul class="sectlevel3">
<li><a href="#_reflection-for-classes">7.4.1. Reflection for Classes</a></li>
<li><a href="#_reflection-for-interfaces">7.4.2. Reflection for Interfaces</a></li>
<li><a href="#_reflection-for-enumerations">7.4.3. Reflection for Enumerations</a></li>
</ul>
</li>
<li><a href="#_conversion-of-primitive-types">7.5. Conversion of primitive types</a></li>
</ul>
</li>
<li><a href="#_expressions">8. Expressions</a>
<ul class="sectlevel2">
<li><a href="#_ecmascript-5-expressions">8.1. ECMAScript 5 Expressions</a>
<ul class="sectlevel3">
<li><a href="#_the-this-literal">8.1.1. The this Literal</a></li>
<li><a href="#_identifier">8.1.2. Identifier</a></li>
<li><a href="#_literals">8.1.3. Literals</a>
<ul class="sectlevel4">
<li><a href="#_integer-literals">8.1.3.1. Integer Literals</a></li>
</ul>
</li>
<li><a href="#_array-literal">8.1.4. Array Literal</a></li>
<li><a href="#_object-literal">8.1.5. Object Literal</a>
<ul class="sectlevel4">
<li><a href="#_properties-6">8.1.5.1. Properties</a></li>
<li><a href="#_scoping-and-linking">8.1.5.2. Scoping and linking</a></li>
</ul>
</li>
<li><a href="#_parenthesized-expression-and-grouping-operator">8.1.6. Parenthesized Expression and Grouping Operator</a></li>
<li><a href="#_property-accessors">8.1.7. Property Accessors</a>
<ul class="sectlevel4">
<li><a href="#properties-1">8.1.7.1. Properties</a></li>
</ul>
</li>
<li><a href="#_new-expression">8.1.8. New Expression</a></li>
<li><a href="#_function-expression-2">8.1.9. Function Expression</a></li>
<li><a href="#_function-calls">8.1.10. Function Calls</a></li>
<li><a href="#_postfix-expression">8.1.11. Postfix Expression</a></li>
<li><a href="#_unary-expression">8.1.12. Unary Expression</a></li>
<li><a href="#_multiplicative-expression">8.1.13. Multiplicative Expression</a></li>
<li><a href="#_additive-expression">8.1.14. Additive Expression</a>
<ul class="sectlevel4">
<li><a href="#type-inference-10">8.1.14.1. Type Inference</a></li>
</ul>
</li>
<li><a href="#_bitwise-shift-expression">8.1.15. Bitwise Shift Expression</a></li>
<li><a href="#_relational-expression">8.1.16. Relational Expression</a></li>
<li><a href="#_equality-expression">8.1.17. Equality Expression</a></li>
<li><a href="#_binary-bitwise-expression">8.1.18. Binary Bitwise Expression</a></li>
<li><a href="#_binary-logical-expression">8.1.19. Binary Logical Expression</a></li>
<li><a href="#_conditional-expression">8.1.20. Conditional Expression</a></li>
<li><a href="#_assignment-expression">8.1.21. Assignment Expression</a></li>
<li><a href="#_comma-expression">8.1.22. Comma Expression</a></li>
</ul>
</li>
<li><a href="#_ecmascript-6-expressions">8.2. ECMAScript 6 Expressions</a>
<ul class="sectlevel3">
<li><a href="#_the-super-keyword">8.2.1. The super Keyword</a></li>
</ul>
</li>
<li><a href="#_ecmascript-7-expressions">8.3. ECMAScript 7 Expressions</a>
<ul class="sectlevel3">
<li><a href="#_await-expression">8.3.1. Await Expression</a></li>
</ul>
</li>
<li><a href="#_n4js-specific-expressions">8.4. N4JS Specific Expressions</a>
<ul class="sectlevel3">
<li><a href="#_class-expression">8.4.1. Class Expression</a></li>
<li><a href="#_cast-as-expression">8.4.2. Cast (As) Expression</a>
<ul class="sectlevel4">
<li><a href="#cast-as-expression-semantics-type-inference">8.4.2.1. Semantics and Type Inference</a></li>
</ul>
</li>
<li><a href="#Import_Calls">8.4.3. Import Calls</a></li>
</ul>
</li>
<li><a href="#compile-time-expressions">8.5. Compile-Time Expressions</a></li>
</ul>
</li>
<li><a href="#_statements">9. Statements</a>
<ul class="sectlevel2">
<li><a href="#_ecmascript-5-statements">9.1. ECMAScript 5 Statements</a>
<ul class="sectlevel3">
<li><a href="#_function-or-field-accessor-bodies">9.1.1. Function or Field Accessor Bodies</a></li>
<li><a href="#_variable-statement">9.1.2. Variable Statement</a></li>
<li><a href="#_if-statement">9.1.3. If Statement</a></li>
<li><a href="#_iteration-statements">9.1.4. Iteration Statements</a></li>
<li><a href="#_return-statement">9.1.5. Return Statement</a></li>
<li><a href="#_with-statement">9.1.6. With Statement</a></li>
<li><a href="#_switch-statement">9.1.7. Switch Statement</a></li>
<li><a href="#_throw-try-and-catch-statements">9.1.8. Throw, Try, and Catch Statements</a></li>
<li><a href="#_debugger-statement">9.1.9. Debugger Statement</a></li>
</ul>
</li>
<li><a href="#_ecmascript-6-statements">9.2. ECMAScript 6 Statements</a>
<ul class="sectlevel3">
<li><a href="#_let">9.2.1. Let</a></li>
<li><a href="#_const">9.2.2. Const</a></li>
<li><a href="#_for-of-statement">9.2.3. <code>for &#8230;&#8203; of</code> statement</a></li>
<li><a href="#_import-statement">9.2.4. Import Statement</a>
<ul class="sectlevel4">
<li><a href="#Dynamic_Imports">9.2.4.1. Dynamic Imports</a></li>
<li><a href="#_immutabilaty-of-imports">9.2.4.2. Immutabilaty of Imports</a></li>
</ul>
</li>
<li><a href="#_export-statement">9.2.5. Export Statement</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_annotations">10. Annotations</a>
<ul class="sectlevel2">
<li><a href="#_introduction-2">10.1. Introduction</a>
<ul class="sectlevel3">
<li><a href="#_syntax-13">10.1.1. Syntax</a></li>
<li><a href="#_properties-7">10.1.2. Properties</a></li>
<li><a href="#_element-specific-annotations">10.1.3. Element-Specific Annotations</a></li>
<li><a href="#_general-annotations">10.1.4. General Annotations</a>
<ul class="sectlevel4">
<li><a href="#_idebug">10.1.4.1. IDEBUG</a></li>
</ul>
</li>
<li><a href="#idebug-syntax">10.1.5. Syntax</a>
<ul class="sectlevel4">
<li><a href="#_semantics-11">10.1.5.1. Semantics</a></li>
<li><a href="#_suppress-warnings">10.1.5.2. Suppress Warnings</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_declaration-of-annotations">10.2. Declaration of Annotations</a></li>
</ul>
</li>
<li><a href="#_extended-fetaures">11. Extended Fetaures</a>
<ul class="sectlevel2">
<li><a href="#_array-and-object-destructuring">11.1. Array and Object Destructuring</a>
<ul class="sectlevel3">
<li><a href="#_syntax-14">11.1.1. Syntax</a></li>
<li><a href="#_semantics-12">11.1.2. Semantics</a></li>
</ul>
</li>
<li><a href="#_dependency-injection">11.2. Dependency Injection</a>
<ul class="sectlevel3">
<li><a href="#_di-components-and-injectors">11.2.1. DI Components and Injectors</a>
<ul class="sectlevel4">
<li><a href="#_dicomponent-relations">11.2.1.1. DIComponent Relations</a></li>
</ul>
</li>
<li><a href="#_binders-and-bindings">11.2.2. Binders and Bindings</a></li>
<li><a href="#_injection-points">11.2.3. Injection Points</a>
<ul class="sectlevel4">
<li><a href="#_field-injection">11.2.3.1. Field Injection</a></li>
<li><a href="#_constructor-injection">11.2.3.2. Constructor Injection</a></li>
<li><a href="#_method-injection">11.2.3.3. Method Injection</a>
<ul class="sectlevel5">
<li><a href="#_provider">11.2.3.3.1. Provider</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_n4js-di-life-cycle-and-scopes">11.2.4. N4JS DI Life Cycle and Scopes</a>
<ul class="sectlevel4">
<li><a href="#_injection-cylces">11.2.4.1. Injection Cylces</a></li>
<li><a href="#_default-scope">11.2.4.2. Default Scope</a></li>
<li><a href="#_singleton-scope">11.2.4.3. Singleton Scope</a></li>
<li><a href="#_per-injection-chain-singleton">11.2.4.4. Per Injection Chain Singleton</a></li>
</ul>
</li>
<li><a href="#_validation-of-callsites-targeting-n4injector-methods">11.2.5. Validation of callsites targeting N4Injector methods</a></li>
<li><a href="#_n4js-di-annotations">11.2.6. N4JS DI Annotations</a>
<ul class="sectlevel4">
<li><a href="#_n4js-di-generateinjector">11.2.6.1. N4JS DI @GenerateInjector</a></li>
<li><a href="#_n4js-di-withparentinjector">11.2.6.2. N4JS DI @WithParentInjector</a></li>
<li><a href="#_n4js-di-usebinder">11.2.6.3. N4JS DI @UseBinder</a></li>
<li><a href="#_n4js-di-binder">11.2.6.4. N4JS DI @Binder</a></li>
<li><a href="#_n4js-di-bind">11.2.6.5. N4JS DI @Bind</a></li>
<li><a href="#_n4js-di-provides">11.2.6.6. N4JS DI @Provides</a></li>
<li><a href="#_n4js-di-inject">11.2.6.7. N4JS DI @Inject</a></li>
<li><a href="#_n4js-di-singleton">11.2.6.8. N4JS DI @Singleton</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_test-support">11.3. Test Support</a></li>
<li><a href="#_polyfill-definitions">11.4. Polyfill Definitions</a>
<ul class="sectlevel3">
<li><a href="#_runtime-polyfill-definitions">11.4.1. Runtime Polyfill Definitions</a></li>
<li><a href="#_static-polyfill-definitions">11.4.2. Static Polyfill Definitions</a></li>
<li><a href="#_transpiling-static-polyfilled-classes">11.4.3. Transpiling static polyfilled classes</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_components">12. Components</a>
<ul class="sectlevel2">
<li><a href="#_overview-2">12.1. Overview</a></li>
<li><a href="#Component_Types">12.2. Component Types</a>
<ul class="sectlevel3">
<li><a href="#_libraries">12.2.1. Libraries</a></li>
<li><a href="#_runtime-environment-and-runtime-libraries">12.2.2. Runtime Environment and Runtime Libraries</a></li>
<li><a href="#_tests">12.2.3. Tests</a></li>
<li><a href="#_type-definitions">12.2.4. Type Definitions</a></li>
</ul>
</li>
<li><a href="#package-json">12.3. Package.json File</a>
<ul class="sectlevel3">
<li><a href="#_basic-properties">12.3.1. Basic Properties</a></li>
<li><a href="#_n4js-properties">12.3.2. N4JS Properties</a></li>
<li><a href="#_constraints">12.3.3. Constraints</a></li>
</ul>
</li>
<li><a href="#_support-for-npm-scopes">12.4. Support for NPM Scopes</a></li>
<li><a href="#sec:N4JS-Type-Definitions">12.5. N4JS Type Definitions</a>
<ul class="sectlevel3">
<li><a href="#_specify-type-definition">12.5.1. Specify Type Definition</a></li>
<li><a href="#_name-conventions">12.5.2. Name Conventions</a></li>
<li><a href="#_version-conventions">12.5.3. Version Conventions</a>
<ul class="sectlevel4">
<li><a href="#_define-a-new-type-definition-package">12.5.3.1. Define a New Type Definition Package</a></li>
<li><a href="#_using-a-type-definition-package">12.5.3.2. Using a Type Definition Package</a></li>
<li><a href="#_rational">12.5.3.3. Rational</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_modules">12.6. Modules</a></li>
<li><a href="#_api-and-implementation-component">12.7. API and Implementation Component</a>
<ul class="sectlevel3">
<li><a href="#_execution-of-api-and-implementation-components">12.7.1. Execution of API and Implementation Components</a></li>
<li><a href="#_api-and-implementation-with-di">12.7.2. API and Implementation With DI</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_plainjs">13. PlainJS</a>
<ul class="sectlevel2">
<li><a href="#_type-inference-and-validation-for-plain-js">13.1. Type Inference and Validation for Plain JS</a></li>
<li><a href="#_external-declarations">13.2. External Declarations</a>
<ul class="sectlevel3">
<li><a href="#_declaring-externals">13.2.1. Declaring externals</a></li>
<li><a href="#_instantiating-external-classes">13.2.2. Instantiating external classes</a></li>
<li><a href="#_implementation-of-external-declarations">13.2.3. Implementation of External Declarations</a></li>
<li><a href="#_example">13.2.4. Example</a></li>
</ul>
</li>
<li><a href="#_global-definitions">13.3. Global Definitions</a></li>
<li><a href="#_runtime-definitions">13.4. Runtime Definitions</a></li>
<li><a href="#_applying-polyfills">13.5. Applying Polyfills</a></li>
</ul>
</li>
<li><a href="#_jsdoc-2">14. JSDoc</a>
<ul class="sectlevel2">
<li><a href="#_general-n4jsdoc-features">14.1. General N4JSDoc Features</a>
<ul class="sectlevel3">
<li><a href="#_provided-inline-tags">14.1.1. Provided Inline Tags</a>
<ul class="sectlevel4">
<li><a href="#jsdoc_tag__code">14.1.1.1. @code</a></li>
<li><a href="#jsdoc_tag__link">14.1.1.2. @link</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_n4jsdoc-for-user-projects">14.2. N4JSdoc for User Projects</a>
<ul class="sectlevel3">
<li><a href="#_standard-tags">14.2.1. Standard Tags</a>
<ul class="sectlevel4">
<li><a href="#_-author">14.2.1.1. @author</a></li>
<li><a href="#jsdoc_tag_param">14.2.1.2. @param</a></li>
<li><a href="#jsdoc_tag_return">14.2.1.3. @return</a></li>
</ul>
</li>
<li><a href="#_test-related-tags">14.2.2. Test Related Tags</a>
<ul class="sectlevel4">
<li><a href="#jsdoc_tag__testee">14.2.2.1. @testee</a></li>
<li><a href="#jsdoc_tag__testeeFromType">14.2.2.2. @testeeFromType</a></li>
<li><a href="#_testeeType_and__testeeMember">14.2.2.3. @testeeType and @testeeMember</a></li>
<li><a href="#jsdoc_tag_reqid_in_Tests">14.2.2.4. @reqid in Tests</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_n4jsdoc-for-api-and-implementation-projects">14.3. N4JSDoc for API and Implementation Projects</a>
<ul class="sectlevel3">
<li><a href="#jsdoc_tag__apiNote">14.3.1. @apiNote</a></li>
<li><a href="#API_Project_Tags">14.3.2. API Project Tags</a>
<ul class="sectlevel4">
<li><a href="#jsdoc_tag_apiState">14.3.2.1. @apiState</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#_jsx">15. JSX</a>
<ul class="sectlevel2">
<li><a href="#_jsx-support">15.1. JSX Support</a></li>
<li><a href="#_jsx-backend">15.2. JSX Backend</a></li>
</ul>
</li>
<li><a href="#_grammars">16. Grammars</a>
<ul class="sectlevel2">
<li><a href="#_type-expressions-grammar">16.1. Type Expressions Grammar</a></li>
<li><a href="#_n4js-language-grammar">16.2. N4JS Language Grammar</a></li>
</ul>
</li>
<li><a href="#_jsobjects">17. JSObjects</a>
<ul class="sectlevel2">
<li><a href="#_object">17.1. Object</a></li>
<li><a href="#_string">17.2. String</a></li>
<li><a href="#_boolean">17.3. Boolean</a></li>
<li><a href="#_number">17.4. Number</a>
<ul class="sectlevel3">
<li><a href="#_static-attributes">17.4.1. Static Attributes</a></li>
</ul>
</li>
<li><a href="#function">17.5. Function</a></li>
<li><a href="#_error">17.6. Error</a></li>
<li><a href="#_array">17.7. Array</a></li>
<li><a href="#_date">17.8. Date</a></li>
<li><a href="#_math">17.9. Math</a>
<ul class="sectlevel3">
<li><a href="#static-attributes-1">17.9.1. Static Attributes</a></li>
</ul>
</li>
<li><a href="#_regexp">17.10. RegExp</a></li>
<li><a href="#_json">17.11. JSON</a></li>
</ul>
</li>
<li><a href="#_n4js-objects">18. N4JS Objects</a>
<ul class="sectlevel2">
<li><a href="#_reflection-model">18.1. Reflection Model</a></li>
<li><a href="#_error-types">18.2. Error Types</a>
<ul class="sectlevel3">
<li><a href="#_n4apinotimplemented">18.2.1. N4ApiNotImplemented</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#_acronyms">Appendix A: Acronyms</a></li>
<li><a href="#sec:License">Appendix B: License</a></li>
<li><a href="#_bibliography">Appendix C: Bibliography</a></li>
</ul>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph center">
<p><strong>Last Updated: 2019-08-08</strong></p>
</div>
<div class="paragraph center">
<p><strong>Authors:</strong><br>
Jens von Pilgrim, Jakub Siberski, Mark-Oliver Reiser, Torsten Krämer, Ákos Kitta, Sebastian Zarnekow, Lorenzo Bettini, Jörg Reichert, Kristian Duske, Marcus Mews, Minh Quang Tran, Luca Beurer-Kellner</p>
</div>
<div style="page-break-after: always;"></div>
<h2 id="_abstract" class="discrete">Abstract</h2>
<div class="paragraph">
<p>This document contains the N4JS Specification.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_introduction"><a class="anchor" href="#_introduction"></a><a class="link" href="#_introduction">1. Introduction</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>This specification defines the N4JS language.</p>
</div>
<div class="paragraph">
<p>In general, the N4JS JavaScript dialect used is identical to the standard ECMAScript as defined in the 6th edition of
ECMA-262, also known as ECMAScript 2015, referred to as [<a href="#ECMA15a">ECMA15a</a>].</p>
</div>
<div class="sect2 language-n4js">
<h3 id="_notation"><a class="anchor" href="#_notation"></a><a class="link" href="#_notation">1.1. Notation</a></h3>
<div class="sect3">
<h4 id="_grammar-notation"><a class="anchor" href="#_grammar-notation"></a><a class="link" href="#_grammar-notation">1.1.1. Grammar Notation</a></h4>
<div class="paragraph">
<p>For the specification of the syntax and structure of elements, we use a
slightly augmented similar to the grammar language of Xtext <a href="http://www.eclipse.org/Xtext/documentation/301_grammarlanguage.html">Grammar Language</a>.</p>
</div>
<div class="paragraph">
<p>Similar to [<a href="#ECMA11a">ECMA11a</a>], we define types with properties only for the purpose of explanation and usage within this specification.
We use the Xtext notation style to assign values to meta-properties.
Particularly, we use the Xtext notation for collection (<code>+=</code>) and boolean (<code>?=</code>) values.
These properties are written in italics. Enumerations are defined similar to Xtext.
In order to allow the specification of default values, which are often defined by omitting the value, we always define the literal explicitly if it can be defined by the user.</p>
</div>
<div class="paragraph">
<p>The following lists informally defines the grammar:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Terminal</dt>
<dd>
<p>Terminals (or terminal strings) are enclosed in single quotes, e.g., <code>terminal</code>.</p>
</dd>
<dt class="hdlist1">Enumerations</dt>
<dd>
<p>Rules which contain only terminals used as values for properties are
marked with <code>enum</code> for enumeration.</p>
</dd>
<dt class="hdlist1">Properties</dt>
<dd>
<p>Values of non-terminals, e.g., other rules, can be assigned to
properties. The property name and the assignment are not part of the
original syntax and only used for the meta description. E.g., <code><em>name=</em>Identifier</code>.</p>
</dd>
<dt class="hdlist1">Collection Properties</dt>
<dd>
<p>If a property is a collection, values are added to that list via <code>+=</code>.
E.g.,<code><em>property+=</em>Value</code> .</p>
</dd>
<dt class="hdlist1">Boolean Properties</dt>
<dd>
<p>Boolean properties are set to false by default, if the value (usually
a terminal) is found, the boolean value is set to true. Often, the
name of the property is similar to the terminal. E.g., <code><em>final?</em>='final'?</code>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Properties of a non-terminal are sometimes listed again below the
grammar. In that case, often pseudo properties are introduced which are
derived from other properties and which are only used for
simplification.</p>
</div>
</div>
<div class="sect3">
<h4 id="_type-judgments-and-rules-and-constraints-notation"><a class="anchor" href="#_type-judgments-and-rules-and-constraints-notation"></a><a class="link" href="#_type-judgments-and-rules-and-constraints-notation">1.1.2. Type Judgments and Rules and Constraints Notation</a></h4>
<div class="sect4">
<h5 id="_typing-rules-and-judgments"><a class="anchor" href="#_typing-rules-and-judgments"></a><a class="link" href="#_typing-rules-and-judgments">1.1.2.1. Typing Rules and Judgments</a></h5>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="rule"></a><strong>Definition:</strong> <a href="#rule">Rule</a></p>
</div>
<div class="paragraph">
<p>We use the common notation for rules such as type inference rules <sup class="footnote">[<a id="_footnoteref_1" class="footnote" href="#_footnote_1" title="View footnote.">1</a>]</sup>, that is</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>p</mi><mi>r</mi><mi>e</mi><mi>m</mi><mi>i</mi><mi>s</mi><mi>e</mi><mi>s</mi></mrow><mrow><mi>c</mi><mi>o</mi><mi>n</mi><mi>c</mi><mi>l</mi><mi>u</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi></mrow></mfrac><mspace width="5.0mm"/><mstyle mathvariant="normal"><mtext>rule name</mtext></mstyle></math>
</div>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>p</mi><mi>r</mi><mi>e</mi><mi>m</mi><mi>i</mi><mi>s</mi><mi>e</mi><mi>s</mi></math> is the rule’s premises (e.g., the expression to be inferred), <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>c</mi><mi>o</mi><mi>n</mi><mi>c</mi><mi>l</mi><mi>u</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi></math> the result of the rule.
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>r</mi><mi>u</mi><mi>l</mi><mi>e</mi><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></math> is an optional condition which may be omitted.</p>
</div>
<div class="paragraph">
<p>Both parts of the rule may contain multiple expressions, which are concatenated via 'and'.</p>
</div>
<div class="paragraph">
<p>For example, the following</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><msub><mi>P</mi><mn>1</mn></msub><mspace width="5.0mm"/><msub><mi>P</mi><mn>2</mn></msub><mspace width="5.0mm"/><msub><mi>P</mi><mn>3</mn></msub></mrow><mi>C</mi></mfrac></math>
</div>
</div>
<div class="paragraph">
<p>can be read as</p>
</div>
<div class="quoteblock">
<blockquote>
if <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>P</mi><mn>1</mn></msub></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>P</mi><mn>2</mn></msub></math>, <em>and</em> <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>P</mi><mn>3</mn></msub></math> are all true, then <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>C</mi></math> is true as well.
</blockquote>
</div>
</div>
</div>
<div class="paragraph">
<p>The following judgments (with relation symbols) are used:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">subtype <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>&lt;</mo></math> </dt>
<dd>
<p>-</p>
</dd>
<dt class="hdlist1">type <math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle></math> </dt>
<dd>
<p>in which the left hand side is a declaration or expression, and the right hand side a type.
We also use <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo>[</mo><mspace width="-0.167em"/><mrow><mo>[</mo></mrow></mrow><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><mrow><mrow><mo>]</mo></mrow><mspace width="-0.167em"/><mo>]</mo></mrow></math> as a function returning the (inferred) type of an expression.</p>
</dd>
<dt class="hdlist1">expectedTypeIn <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mi>:</mi></math> </dt>
<dd>
<p>a relation with three arguments:
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>c</mi><mi>o</mi><mi>n</mi><mi>t</mi><mi>a</mi><mi>i</mi><mi>n</mi><mi>e</mi><mi>r</mi><mo></mo><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi><mi>:</mi><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> means, that
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>e</mi><mi>x</mi><mi>p</mi><mi>r</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi>i</mi><mi>o</mi><mi>n</mi></math> is expected to be a subtype of
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> inside <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>c</mi><mi>o</mi><mi>n</mi><mi>t</mi><mi>a</mi><mi>i</mi><mi>n</mi><mi>e</mi><mi>r</mi></math></p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>The following statement, for example, defines transitivity of subtypes
(in a simplified manner):</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mi>Γ</mi><mo></mo><mi>B</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi><mspace width="5.0mm"/><mi>Γ</mi><mo></mo><mi>C</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>B</mi></mrow><mrow><mi>Γ</mi><mo></mo><mi>C</mi><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>A</mi></mrow></mfrac></math>
</div>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math> is the context containing (bound) type variables etc., <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math> can be read as <code>entails</code>.
Thus, the rule can be read as follows:</p>
</div>
<div class="quoteblock">
<blockquote>
if the type B is a subtype of type A in context <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>Γ</mi></math> (i.e. with constraints on type variables specified in <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>Γ</mi></math>), and if type C is a subtype of B, then C is also a subtype of A in context <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>Γ</mi></math>.
</blockquote>
</div>
<div class="paragraph">
<p>In rules, we sometimes omit the environment if it is not needed.
New information is sometimes added to the environment, in particular, substitutions (that is binding type variables to a type).
The set of substitutions is written with <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>θ</mi></math> (theta).
If new substitutions are explicitly added to that set, we write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>θ</mi><mfenced close=")" open="("><mrow><mi>V</mi><mo></mo><mi>T</mi></mrow></mfenced></math> (<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>V</mi></math> is substituted with type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi></math>).
Often, these bindings are computed from a parameterized type reference which declares type arguments which are bound to the type variables of the generic declaration.
In this case we simply write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>θ</mi><mfenced close=")" open="("><mi>p</mi></mfenced></math>, in which <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>p</mi></math> is the parameterized type declaration.
As these new substitutions must become part of a (newly) created environment, we then usually write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>Γ</mi><mo></mo><mi>θ</mi><mfenced close=")" open="("><mi>p</mi></mfenced></math>.
These substitutions are usually omitted.</p>
</div>
</div>
<div class="sect4">
<h5 id="_types-of-an-element"><a class="anchor" href="#_types-of-an-element"></a><a class="link" href="#_types-of-an-element">1.1.2.2. Types of an Element</a></h5>
<div class="paragraph">
<p>A variable or other typed element may be associated with three types:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Declared type: the type explicitly specified in the code, e.g., <code>var s: string</code>.</p>
</li>
<li>
<p>Inferred type: the type inferred by the type inferencer, e.g., <code>var s = "Hello"</code> infers the type of s to <code>string</code>. I.e.
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>Γ</mi><mo></mo><mi>s</mi><mi>:</mi><mrow><mi>s</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>g</mi></mrow></math> will be true, or <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo>[</mo><mspace width="-0.167em"/><mrow><mo>[</mo></mrow></mrow><mi>s</mi><mrow><mrow><mo>]</mo></mrow><mspace width="-0.167em"/><mo>]</mo></mrow><mspace width="1.0mm"/><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>:</mtext></mstyle><mspace width="1.0mm"/><mi>s</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>g</mi></math>.
If an element is annotated with a type ,i.e. it has a declared type, the inferred type will always be the declared type.</p>
</li>
<li>
<p>Actual type: the actual type of a variable during runtime.
This type information is not available at compile time and ignored in this specification.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>These types are not type declarations but type references, in fact, as they may be parameterized.
For the sake of simplicity, we often omit the <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi><mi>e</mi><mi>f</mi></math> suffix to shorten formulas.
Consequently, we define the following properties and pseudo properties for typed elements such as variables:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">declaredType<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi><mi>e</mi><mi>f</mi></math> </dt>
<dd>
<p>The explicitly declared type, this is usually a real property of the construct.
Not all elements allow the specification of a declared type, such as expressions.</p>
</dd>
<dt class="hdlist1">inferredType<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi><mi>e</mi><mi>f</mi></math> or <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo>[</mo><mspace width="-0.167em"/><mrow><mo>[</mo></mrow></mrow><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><mrow><mrow><mo>]</mo></mrow><mspace width="-0.167em"/><mo>]</mo></mrow></math></dt>
<dd>
<p>This pseudo property is the inferred type computed by the type inferencer.</p>
</dd>
<dt class="hdlist1">type<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>R</mi><mi>e</mi><mi>f</mi></math> </dt>
<dd>
<p>A pseudo property for elements with a <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>d</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> property.
It is similar to the inferred type, i.e. <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>e</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo>=</mo><mrow><mo>[</mo><mspace width="-0.167em"/><mrow><mo>[</mo></mrow></mrow><mi>e</mi><mrow><mrow><mo>]</mo></mrow><mspace width="-0.167em"/><mo>]</mo></mrow></math></p>
</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_auxiliary-functions"><a class="anchor" href="#_auxiliary-functions"></a><a class="link" href="#_auxiliary-functions">1.2. Auxiliary Functions</a></h3>
<div class="paragraph">
<p>This section describes some auxiliary functions required for definition of type inference rules later on.</p>
</div>
<div class="sect3">
<h4 id="_binding"><a class="anchor" href="#_binding"></a><a class="link" href="#_binding">1.2.1. Binding</a></h4>
<div class="paragraph">
<p>Binding an identifier (variable reference) to a variable declaration (or
variable definition) is not part of this specification as this is
standard ECMAScript functionality. However, some valid ECMAScript
bindings are permitted due to visibility constraints.</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="binding_relation"></a><strong>Definition:</strong> <a href="#binding_relation">Binding Relation</a></p>
</div>
<div class="paragraph">
<p>We define a pseudo relation</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>b</mi><mi>i</mi><mi>n</mi><mi>d</mi><mi>:</mi><mi>V</mi><mi>a</mi><mi>r</mi><mi>i</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>e</mi><mi>r</mi><mi>e</mi><mi>n</mi><mi>c</mi><mi>e</mi><mo>×</mo><mi>V</mi><mi>a</mi><mi>r</mi><mi>i</mi><mi>a</mi><mi>b</mi><mi>l</mi><mi>e</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>a</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi></math>
</div>
</div>
<div class="paragraph">
<p>which binds a reference, i.e. an identifier, to a declaration (e.g.,variable declaration).</p>
</div>
<div class="paragraph">
<p>Binding of variable references to declaration is defined by ECMAScript already.
Type references only occur in type expressions, how these are handled is explained in <a href="#_type-expressions">Type Expressions</a>.</p>
</div>
<div class="paragraph">
<p>We usually omit this binding mechanism in most rules and use the reference similarly to the declaration or definition it is bound to.
If a variable reference <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>r</mi></math>, for example, is bound to a variable declaration <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>D</mi></math>, i.e. <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>b</mi><mi>i</mi><mi>n</mi><mi>d</mi><mfenced close=")" open="("><mi>r</mi><mi>D</mi></mfenced></math>, we simply write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>r</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> instead of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>b</mi><mi>i</mi><mi>n</mi><mi>d</mi><mfenced close=")" open="("><mi>r</mi><mi>D</mi></mfenced><mo>,</mo><mi>D</mi><mo>.</mo><mi>t</mi><mi>y</mi><mi>p</mi><mi>e</mi></math> to refer to the type expression
(of the variable).<sup class="footnote">[<a id="_footnoteref_2" class="footnote" href="#_footnote_2" title="View footnote.">2</a>]</sup></p>
</div>
</div>
</div>
<div class="paragraph">
<p>A <code>DeclaredType</code> references the type declaration by its simple name that has been imported from a module specifier.
We define the method <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>b</mi><mi>i</mi><mi>n</mi><mi>d</mi></math> for declared types as well:</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="binding_relation_of_types"></a><strong>Definition:</strong> <a href="#binding_relation_of_types">Binding Relation of Types</a></p>
</div>
<div class="paragraph">
<p>We define a pseudo relation</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>b</mi><mi>i</mi><mi>n</mi><mi>d</mi><mi>:</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>e</mi><mi>d</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo>×</mo><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi><mo>|</mo><mi>I</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>r</mi><mi>f</mi><mi>a</mi><mi>c</mi><mi>e</mi><mo>|</mo><mi>E</mi><mi>n</mi><mi>u</mi><mi>m</mi></math>
</div>
</div>
<div class="paragraph">
<p>which binds a type reference, i.e. a simple name, to the type declaration.</p>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_merging-types"><a class="anchor" href="#_merging-types"></a><a class="link" href="#_merging-types">1.2.2. Merging Types</a></h4>
<div class="paragraph">
<p>In some cases we have to merge types, e.g., types of a union type or item types of an array.
For that purpose, we define a method <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>m</mi><mi>e</mi><mi>r</mi><mi>g</mi><mi>e</mi></math> as follows.</p>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="merge_function"></a><strong>Definition:</strong> <a href="#merge_function">Merge Function</a></p>
</div>
<div class="paragraph">
<p>We define a pseudo function</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>m</mi><mi>e</mi><mi>r</mi><mi>g</mi><mi>e</mi><mi>:</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo>×</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>×</mo><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mo></mo><mi mathvariant="script">P</mi><mfenced close=")" open="("><mrow><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></mrow></mfenced></math>
</div>
</div>
<div class="paragraph">
<p>The idea of this function is to remove duplicates.
For example; if a union type contains two type expressions <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><msub><mi>e</mi><mn>1</mn></msub></math> and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>t</mi><msub><mi>e</mi><mi>k</mi></msub></math>, and if <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>τ</mi><mfenced close=")" open="("><mrow><mi>t</mi><msub><mi>e</mi><mn>1</mn></msub></mrow></mfenced><mo>=</mo><mi>τ</mi><mfenced close=")" open="("><mrow><mi>t</mi><msub><mi>e</mi><mn>2</mn></msub></mrow></mfenced></math>, then <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>m</mi><mi>e</mi><mi>r</mi><mi>g</mi><mi>e</mi><mfenced close=")" open="("><mrow><mi>τ</mi><mfenced close=")" open="("><mrow><mi>t</mi><msub><mi>e</mi><mn>1</mn></msub></mrow></mfenced></mrow><mrow><mi>τ</mi><mfenced close=")" open="("><mrow><mi>t</mi><msub><mi>e</mi><mn>2</mn></msub></mrow></mfenced></mrow></mfenced></math> contains only one element.
The order of the elements is lost, however.</p>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_logic-formulas"><a class="anchor" href="#_logic-formulas"></a><a class="link" href="#_logic-formulas">1.2.2.1. Logic Formulas</a></h5>
<div class="paragraph">
<p>In general, we use a pragmatic mixture of pseudo code, predicate logic, and OCL.
Within constraints (also within the inference rules), the properties defined in the grammar are used.</p>
</div>
<div class="paragraph">
<p>In some rules, it is necessary to type the rule variables.
Instead of explicitly checking the metatype (via <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>μ</mi><mfenced close=")" open="("><mi>X</mi></mfenced><mo>=</mo><mi>:</mi><mrow><mi>M</mi><mi>e</mi><mi>t</mi><mi>a</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></mrow></math>), we precede the variable with the type, that is: <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>M</mi><mi>e</mi><mi>t</mi><mi>a</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi></mrow><mi>X</mi></math>.</p>
</div>
<div class="paragraph">
<p>Instead of "type casting" elements, often properties are simply accessed.
If an element does not define that element, it is either assumed to be false or null by default.</p>
</div>
<div class="paragraph">
<p>If a property <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>p</mi></math> is optional and not set, we write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>p</mi><mo>=</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></math> to test its absence.
Note that <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>p</mi><mo>=</mo><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></math> is different from <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>p</mi><mo>=</mo><mi>N</mi><mi>u</mi><mi>l</mi><mi>l</mi></math>, as the latter refers to the null type.
Non-terminals may implicitly be subclasses.
In that case, the concrete non-terminal, or type, of a property may be subject for a test in a constraint.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_symbols-and-font-convention"><a class="anchor" href="#_symbols-and-font-convention"></a><a class="link" href="#_symbols-and-font-convention">1.2.3. Symbols and Font Convention</a></h4>
<div class="paragraph">
<p>Variables and their properties are printed in italic when used in formulas (such as rules).
A dot-notation is used for member access, e.g. <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>v</mi><mo>.</mo><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi></math>.
Also defined functions are printed in italic, e.g., <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>a</mi><mi>c</mi><mi>c</mi><mfenced close=")" open="("><mi>r</mi><mi>D</mi></mfenced></math>.
Properties which define sets are usually ordered and we assume 0-indexed access to elements, the index subscripted, e.g., <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>v</mi><mo>.</mo><mi>m</mi><mi>e</mi><mi>t</mi><mi>h</mi><mi>o</mi><mi>d</mi><msub><mi>s</mi><mi>i</mi></msub></math>.</p>
</div>
<div class="paragraph">
<p>We use the following symbols and font conventions:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>¬</mo></math></dt>
<dd>
<p>Logical and, or, exclusive or (xor), and not.</p>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="bold"><mtext>if</mtext></mstyle><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="bold"><mtext>then</mtext></mstyle><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="bold"><mtext>else</mtext></mstyle><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></math> </dt>
<dd>
<p>Logical implication, if and only if, and if-then-else.</p>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>true</mtext></mstyle></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>false</mtext></mstyle></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle mathvariant="monospace"><mtext>null</mtext></mstyle></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi></mi></math></dt>
<dd>
<p>Boolean true, boolean false, null (i.e., not specified, e.g.,
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>v</mi><mo>.</mo><mi>s</mi><mi>u</mi><mi>p</mi><mo>=</mo></math> means that there are is no <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi><mi>u</mi><mi>p</mi></math>
(super class) specified), empty set.</p>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>|</mo><mi>x</mi><mo>|</mo></math></dt>
<dd>
<p>Element of, not an element of, union set, intersection set,
cardinality of set x.</p>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="script">P</mi><mfenced close=")" open="("><mi>X</mi></mfenced></math></dt>
<dd>
<p>Power set of <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>X</mi></math>, i.e.
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="script">P</mi><mfenced close=")" open="("><mi>X</mi></mfenced><mo>=</mo><mfenced close="}" open="{"><mrow><mi>U</mi><mi>:</mi><mi>U</mi><mo></mo><mi>X</mi></mrow></mfenced></math>.</p>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math>, <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo></math></dt>
<dd>
<p>Exists, not exists, for all; we write <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mi>x</mi><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><mi>z</mi><mi>:</mi><mi>P</mi><mfenced close=")" open="("><mi>x</mi><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow><mi>z</mi></mfenced></math> and say</p>
<div class="quoteblock">
<blockquote>
"there exists <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>x</mi><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><mi>z</mi></math> such that predicate <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>P</mi></math> is true".
</blockquote>
</div>
<div class="paragraph">
<p>Note that <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mi>x</mi><mi>:</mi><mi>P</mi><mfenced close=")" open="("><mi>x</mi></mfenced><mo></mo><mo></mo><mi>x</mi><mi>:</mi><mo>¬</mo><mi>P</mi><mfenced close=")" open="("><mi>x</mi></mfenced></math>.</p>
</div>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>μ</mi><mfenced close=")" open="("><mrow><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></mrow></mfenced></math></dt>
<dd>
<p>(mu) read "<strong>metatype of</strong>"; metatype of a variable or property, e.g.,</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mstyle mathvariant="bold"><mtext>if</mtext></mstyle><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mi>μ</mi><mfenced close=")" open="("><mi>x</mi></mfenced><mo>=</mo><mi>:</mi><mrow><mi>C</mi><mi>l</mi><mi>a</mi><mi>s</mi><mi>s</mi></mrow><mstyle mathvariant="bold"><mtext>then</mtext></mstyle><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mstyle mathvariant="bold"><mtext>else</mtext></mstyle><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/></math>
</div>
</div>
</dd>
<dt class="hdlist1"><math xmlns="http://www.w3.org/1998/Math/MathML"><mover accent="true"><mi>x</mi><mo>¯</mo></mover></math></dt>
<dd>
<p>Sequence of elements <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>x</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>x</mi><mi>n</mi></msub></math>. E.g., if we want to
define a constraint that the owner of a members of a class
<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>C</mi></math> is the class, we simply write</p>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>C</mi><mo>.</mo><mover accent="true"><mrow><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi></mrow><mo>¯</mo></mover><mo>.</mo><mi>o</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>r</mi><mo>=</mo><mi>C</mi></math>
</div>
</div>
<div class="paragraph">
<p>instead of</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo></mo><mi>m</mi><mo></mo><mi>C</mi><mo>.</mo><mi>m</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>s</mi><mi>:</mi><mi>m</mi><mo>.</mo><mi>o</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>r</mi><mo>=</mo><mi>C</mi></math>
</div>
</div>
<div class="paragraph">
<p>or even more complicated with index variables.</p>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Sequences are 1-based, e.g., a sequence <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>s</mi></math> with length <math xmlns="http://www.w3.org/1998/Math/MathML"><mo>|</mo><mi>s</mi><mo>|</mo><mo>=</mo><mi>n</mi></math>, has elements <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>s</mi><mn>1</mn></msub><mo>,</mo><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>.</mo><mspace width="1.0mm"/><mo>,</mo><msub><mi>s</mi><mi>n</mi></msub></math>.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_grammar"><a class="anchor" href="#_grammar"></a><a class="link" href="#_grammar">2. Grammar</a></h2>
<div class="sectionbody">
<div class="sect2 language-n4js">
<h3 id="_lexical-conventions"><a class="anchor" href="#_lexical-conventions"></a><a class="link" href="#_lexical-conventions">2.1. Lexical Conventions</a></h3>
<div class="paragraph">
<p>As a super language on top of ECMAScript, the same lexical conventions are supported as described in [<a href="#ECMA11a">ECMA11a(p.S7)</a>] within strict mode.
Some further constraints are defined, however, restricting certain constructs. These constraints are described in the following.</p>
</div>
<div class="sect3">
<h4 id="_identifier-names-and-identifiers"><a class="anchor" href="#_identifier-names-and-identifiers"></a><a class="link" href="#_identifier-names-and-identifiers">2.1.1. Identifier Names and Identifiers</a></h4>
<div class="paragraph">
<p>Cf. [<a href="#ECMA11a">ECMA11a(p.S7.6)</a>], [<a href="#ECMA11a">ECMA11a(p.S11.1.2, p.p.63)</a>] and [<a href="#ECMA11a">ECMA11a(p.S01.2, p.p.51ff)</a>].</p>
</div>
<div class="paragraph">
<p>As a reminder, identifiers are defined as follows in the ECMAScript specification:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">IdentifierName: IdentifierStart* IdentifierPart;
IdentifierStart : UnicodeLetter | '_';
\ UnicodeEscapeSequence</code></pre>
</div>
</div>
<div class="paragraph">
<p>N4JS supports a limited form of computed-names for member declarations:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">N4JSPropertyComputedName:
'[' (SymbolLiteralComputedName | StringLiteralComputedName) ']'
;
SymbolLiteralComputedName: N4JSIdentifier '.' N4JSIdentifier ;
StringLiteralComputedName: STRING ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>As can be seen, a computed-name must be either</p>
</div>
<div class="ulist">
<ul>
<li>
<p>a symbol reference, e.g., <code>Symbol.iterator</code></p>
</li>
<li>
<p>a string literal, i.e., a compile time known constant.
This notation is useful when interoperating with libraries that define members whose names contain special characters (e.g., a field name starting with commercial-at)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>In N4JS, identifiers are further constrained in order to avoid ambiguities and to make code more readable.
Some of these constraints will lead to errors, others only to warnings.
They do not apply for identifiers declared in definitions file (n4jsd) in order to enable declaration of external entities.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-1"></a><strong>Req. IDE-1:</strong> <a href="#Req-IDE-1">N4JS Identifier Restrictions</a> (ver. 1)</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>If the following constraints do not hold, errors are created.</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>Leading <code>$</code> (dollar sign) character is prohibited for any variable name such as fields, variables, types functions and methods.</p>
</li>
<li>
<p>Leading <code>_</code> (underscore) character is not allowed for identifying any functions or methods.</p>
</li>
</ol>
</div>
</li>
</ol>
</div>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-2"></a><strong>Req. IDE-2:</strong> <a href="#Req-IDE-2">N4JS identifier recommendations</a> (ver. 1)</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>If the following constraints do not hold, warnings are created.</p>
</li>
<li>
<p>Variable names should, in general, be constructed form the 26 ASCII upper and lower case alphabetic letters (a..z, A..Z), from the 10 decimal digits (0..9) and from the <code>_</code> (underscore).
Although the usage of the international characters are allowed (according to the ECMAScript specification)
it is discouraged because these characters may not be read or understood well in every circumstance <sup class="footnote">[<a id="_footnoteref_3" class="footnote" href="#_footnote_3" title="View footnote.">3</a>]</sup>.</p>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Type (and Type Variable) Identifiers</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">TypeIdentifier: [_A-Z][_a-zA-Z0-9]*
TypeVariableIdentifier: [_A-Z][_a-zA-Z0-9]*</code></pre>
</div>
</div>
</li>
<li>
<p>Package Identifiers</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">PackageIdentifier: [_a-z][._a-zA-Z0-9]*; // i.e. the folder names, must not end with .</code></pre>
</div>
</div>
</li>
<li>
<p>Member Identifiers and Enum Literals</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">InstanceFieldIdentifier: [_a-z][_a-zA-Z0-9]*
StaticFieldIdentifier: [_A-Z][_A-Z0-9]*([_A-Z0-9]+)*
EnumLiteral: [_A-Z][_A-Z0-9]*([_A-Z0-9]+)*</code></pre>
</div>
</div>
</li>
<li>
<p>Variable and Parameter Names</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">VariableIdentifier: [_a-zA-Z0-9]*
􏰀ParameterIdentifier: [_a-z][_a-zA-Z0-9]*</code></pre>
</div>
</div>
</li>
<li>
<p>Methods</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">MethodIdentifier: [_a-z][_a-zA-Z0-9]*;</code></pre>
</div>
</div>
</li>
<li>
<p>Annotations</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">AnnotationIdentifier: [_A-Z][_a-zA-Z0-9]*</code></pre>
</div>
</div>
</li>
</ol>
</div>
</li>
</ol>
</div>
<div class="paragraph">
<p>The following rules describe how fully qualified names of elements are created.
Note that these fully qualified names cannot be used in N4JS directly.
Though they may be shown in error messages etc. to identify elements.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">TypeIdentifier: [A-Z][a-zA-Z0-9]*;
PackageIdentifier: [a-z][a-zA-Z0-9]*;
FQNType: (PackageIdentifier '.')+ TypeIdentifier;</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_this-keyword"><a class="anchor" href="#_this-keyword"></a><a class="link" href="#_this-keyword">2.1.2. This Keyword</a></h4>
<div class="paragraph">
<p>Cf. [<a href="#ECMA11a">ECMA11a(p.S11.1.1, p.p.63)</a>]</p>
</div>
</div>
<div class="sect3">
<h4 id="_regular-expression-literals"><a class="anchor" href="#_regular-expression-literals"></a><a class="link" href="#_regular-expression-literals">2.1.3. Regular Expression Literals</a></h4>
<div class="paragraph">
<p>Cf. [<a href="#ECMA11a">ECMA11a(p.S7.8.5)</a>]</p>
</div>
</div>
<div class="sect3">
<h4 id="_automatic-semicolon-insertion"><a class="anchor" href="#_automatic-semicolon-insertion"></a><a class="link" href="#_automatic-semicolon-insertion">2.1.4. Automatic Semicolon Insertion</a></h4>
<div class="paragraph">
<p>Cf. [<a href="#ECMA11a">ECMA11a(p.S7.9)</a>]</p>
</div>
<div class="paragraph">
<p><a href="#_acronyms">ASI</a> is supported by the parser, however warnings are issued.</p>
</div>
</div>
<div class="sect3">
<h4 id="_jsdoc"><a class="anchor" href="#_jsdoc"></a><a class="link" href="#_jsdoc">2.1.5. JSDoc</a></h4>
<div class="paragraph">
<p>JSDoc are comments similar to JavaDoc in Java for documenting types, functions and members.
There is no semantic information expressed in JSDoc, that is, the behavior of a program must not change if all the JSDoc is removed.
The JSDoc tags and overall syntax is a mixture of tags defined by the <a href="https://developers.google.com/closure/compiler/docs/js-for-compiler">Google Closure Compiler</a>, Java&#8217;s <a href="http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html">JavaDoc</a> tool and N4-specific tags.</p>
</div>
<div class="paragraph">
<p>JSDoc comments are multiline comments, starting with <code>/**</code> (instead of simple multiline comments, starting with <code>/*</code>).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">MultiLineComment: '/*' MultiLineCommentChars? '*/' // from ECMAScript specification
JSDoc: '/**' MultiLineCommentChars? '*/'</code></pre>
</div>
</div>
<div class="paragraph">
<p>In general, JSDoc comments are placed directly before the annotated language element.
In some cases, this is slightly different, such as for method parameters, for example, where it is then explicitly specified.</p>
</div>
<div class="paragraph">
<p>The content of JSDoc comments will be covered in more detail in upcoming chapters.
For documentation purposes, multi- and single-line descriptions are used in several constructs.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">MLVALUE: ([^@]+[^\n]+)+;
SLVALUE: ([^\n]+);</code></pre>
</div>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>MLVALUE</code> </dt>
<dd>
<p>short for <code>multi-line value</code>. This is usually only used for the general description of types or members.</p>
</dd>
<dt class="hdlist1"><code>SLVALUE</code> </dt>
<dd>
<p>short for <code>single-line value</code>. This is a description which ends at the end of a line.
It is usually used in combination with other tags, e.g., to further describe a parameter of a method.</p>
</dd>
</dl>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_names"><a class="anchor" href="#_names"></a><a class="link" href="#_names">3. Names</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p><em>Visibility</em> defines the scope in which a declaration is visible, that is in which context references can be bound to the declaration.
<em>Access control</em> defines the extent to which types and members are accessible beyond their immediate context.
Access control may, therefore, restrict the visibility of a declaration by limiting its scope.</p>
</div>
<div class="paragraph">
<p><em>Extensibility</em> refers to whether a given type can be subtyped, or in the case of members, whether they can be overridden.
Access control is a prerequisite for extensibility which is further explained in <a href="#_n4js-specific-classifiers">N4JS Specific Classifiers</a></p>
</div>
<div class="sect2 language-n4js">
<h3 id="_access-control"><a class="anchor" href="#_access-control"></a><a class="link" href="#_access-control">3.1. Access Control</a></h3>
<div class="paragraph">
<p>Types from one project may or may not be made accessible to another project.
Likewise, members from a given type may or may not be made accessible to members existing outside that type.
For example, if a developer writes an application which uses a library, which types within that library can the application see?
Given a type that is set as visible, which members of that type can the application see?</p>
</div>
<div class="paragraph">
<p>Accessing a type or member actually means that a reference is bound to a
declaration with the same identifier.</p>
</div>
<div class="paragraph">
<p>We distinguish the following contexts from which an element is accessed
as follows:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p><strong>Module or type</strong>: access from elements in the same module or type.</p>
</li>
<li>
<p><strong>Subtype</strong>: access from a subtype.</p>
</li>
<li>
<p><strong>Project</strong>: access from the same project.</p>
</li>
<li>
<p><strong>Vendor</strong>: access from different project of the same vendor.</p>
</li>
<li>
<p><strong>World</strong>: access from anything else.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Accessibility is defined by modifiers on types and members, e.g <code>public</code>, <code>protected</code>, <code>project</code>, <code>private</code>, via the <code>export</code> statement, and by the <code>@Internal</code> annotation.
Extensibility is defined by the <code>@Final</code> annotation respectively.</p>
</div>
</div>
<div class="sect2 language-n4js">
<h3 id="_accessibility-of-types-top-level-variables-and-function-declarations"><a class="anchor" href="#_accessibility-of-types-top-level-variables-and-function-declarations"></a><a class="link" href="#_accessibility-of-types-top-level-variables-and-function-declarations">3.2. Accessibility of Types, Top-Level Variables and Function Declarations</a></h3>
<div class="paragraph">
<p>We define types (classes, interfaces, enums) whereby each type has members (fields and methods, depending on the kind of type).
When we define a type, we need to define whether it is visible only for the specifying module, project or whether that type should be accessible from outside of that project.</p>
</div>
<div class="paragraph">
<p>The same is true for variable declarations and function declarations defined as top-level elements of a module.</p>
</div>
<div class="paragraph">
<p>The following type access modifiers are supported by N4JS:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">enum TypeAccessModifier: project
| public;</code></pre>
</div>
</div>
<div class="paragraph">
<p>If a type is not exported, its visibility is private.
If a type has declared visibility <code>public</code>, it may additionally be marked as internal via the annotation <code>@Internal</code>.
Thus, we have the following set of type access modifiers:</p>
</div>
<div class="paragraph">
<p>TAM = <code>private</code> <code>project</code> <code>public@Internal</code> <code>public</code></p>
</div>
<div class="paragraph">
<p>That is, in N4JS, only the type access modifiers and are available.
The redundant <code>project</code> modifier serves only documentation purpose and can be synthesized if the <code>export</code> modifier is preset.</p>
</div>
<div class="paragraph">
<p>All other modifiers used here are synthesized as shown in the next example:</p>
</div>
<div class="listingblock">
<div class="title">Synthesized Type Access Modifiers in N4JS</div>
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class C0 {} // private
export class C1 {} // project
export project class C1 {} // project
export @Internal public class C1 {} // public@Internal
export public class C2 {} // public
var v0; // private
export var v1; // project
export project var v1; // project
export @Internal public var v3; // public@Internal
export public var v2; // public
function f0() {} // private
export function f1() {} // project
export project function f1() {} // project
export @Internal public function f3() {} // public@Internal
export public function f2() {} // public</code></pre>
</div>
</div>
<div class="paragraph">
<p>The access control levels are defined as listed in <a href="#tab:type-access-control">Type Access Control</a>.</p>
</div>
<table id="tab:type-access-control" class="tableblock frame-all grid-all spread">
<caption class="title">Table 1. Type Access Control</caption>
<colgroup>
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 20%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-center valign-top" colspan="5"><strong>Type Access</strong></th>
</tr>
</thead>
<tbody>
<tr>
<th class="tableblock halign-center valign-top"><p class="tableblock">Modifier</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">Module</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">Project</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">Vendor</p></th>
<th class="tableblock halign-center valign-top"><p class="tableblock">World</p></th>
</tr>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>private</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>project</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>public@Internal</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top"><p class="tableblock"><code>public</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><code>TAM</code> is a totally ordered set:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mstyle mathvariant="monospace"><mtext>private</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>project</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>public@Internal</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>public</mtext></mstyle></math>
</div>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-3"></a><strong>Req. IDE-3:</strong> <a href="#Req-IDE-3">Type Access Modifiers</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>The following constraints for type access modifiers for a given type <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi></math> (which may be a classifier declaration, a function or a variable) must hold:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>It is an error if <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>T</mi></math> is not exported but defined as <code>project</code>, <code>public</code> or <code>public@Internal</code>.</p>
</li>
<li>
<p>It is an error if an annotation <code>@Internal</code> is present on a module private or <code>project</code> visible type.</p>
</li>
<li>
<p>The type modifier for all built-in ECMAScript types is <code>public</code>.</p>
</li>
<li>
<p>The <em>default modifier</em> for user declared exported declarations is <code>project</code>.
That is, this modifier is assumed if no modifier is explicitly specified.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="type_accessibility_t"></a><strong>Definition:</strong> <a href="#type_accessibility_t">Type Accessibility T</a></p>
</div>
<div class="paragraph">
<p>The function <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>α</mi><mi>T</mi></msub><mi>:</mi><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>e</mi><mi>r</mi><mi>e</mi><mi>n</mi><mi>c</mi><mi>e</mi><mo>×</mo><mi>T</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>a</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo></mo><mi>B</mi><mi>o</mi><mi>o</mi><mi>l</mi><mi>e</mi><mi>a</mi><mi>n</mi></math> computes whether a given type, (top-level) variable or function
reference can access the declaration that it references.
<math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>α</mi><mi>T</mi></msub></math> is defined with <a href="#tab:type-access-control">Type Access Control</a>.</p>
</div>
<div class="paragraph">
<p>Formally, we define <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>α</mi><mi>T</mi></msub></math> for a given reference <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>r</mi></math> and a module top level variable, function or type declaration <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>D</mi></math> as follows <sup class="footnote">[<a id="_footnoteref_4" class="footnote" href="#_footnote_4" title="View footnote.">4</a>]</sup>:</p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>D</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>public</mtext></mstyle></mrow><mrow><msub><mi>α</mi><mi>T</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>D</mi></mfenced></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>D</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>public@Internal</mtext></mstyle><mspace width="3.0mm"/><mi>r</mi><mo>.</mo><mi>v</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>o</mi><mi>r</mi><mo>=</mo><mi>D</mi><mo>.</mo><mi>v</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>o</mi><mi>r</mi></mrow><mrow><msub><mi>α</mi><mi>T</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>D</mi></mfenced></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>D</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>project</mtext></mstyle><mspace width="3.0mm"/><mi>r</mi><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>j</mi><mi>e</mi><mi>c</mi><mi>t</mi><mo>=</mo><mi>D</mi><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>j</mi><mi>e</mi><mi>c</mi><mi>t</mi></mrow><mrow><msub><mi>α</mi><mi>T</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>D</mi></mfenced></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>D</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>private</mtext></mstyle><mspace width="3.0mm"/><mi>r</mi><mo>.</mo><mi>m</mi><mi>o</mi><mi>d</mi><mi>u</mi><mi>l</mi><mi>e</mi><mo>=</mo><mi>D</mi><mo>.</mo><mi>m</mi><mi>o</mi><mi>d</mi><mi>u</mi><mi>l</mi><mi>e</mi></mrow><mrow><msub><mi>α</mi><mi>T</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>D</mi></mfenced></mrow></mfrac></math></p>
</div>
<div class="paragraph">
<p>If the type of the arguments is clear from the context, we simply write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>α</mi><mfenced close=")" open="("><mi>r</mi><mi>D</mi></mfenced></math> instead of <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>α</mi><mi>T</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>D</mi></mfenced></math>.</p>
</div>
<div class="paragraph">
<p>Accessibility for types is only checked for types that manifest themselves in the concrete syntax of the N4JS file.
Types that do not have to be written to concrete syntax may be used even if they are generally not accessible.
This is illustrated by <a href="#ex:implicit-type-references">Implicit, allowed type references in N4JS</a>:</p>
</div>
<div id="ex:implicit-type-references" class="exampleblock">
<div class="title">Example 1. Implicit, allowed type references in N4JS</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">export public class D {
public takeC(): C { .. }
public acceptC(c: C): void { .. }
}
/* private */ class C {}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">var d: D = new D()
d.acceptC( d.takeC() )</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_accessibility-of-members"><a class="anchor" href="#_accessibility-of-members"></a><a class="link" href="#_accessibility-of-members">3.2.1. Accessibility of Members</a></h4>
<div class="paragraph">
<p>Accessibility at the member level is only applicable when the type itself is accessible.
If you cannot access the type, you cannot access any of its members.
Note that inherited members (from an interface or class) become members of a class.
For example, if <code>B extends A</code>, and if <code>A</code> is not accessible to some client <code>C</code> but <code>B</code> is, then the members of <code>A</code> are indirectly accessible to <code>C</code> in so far as they are accessed via <code>B</code>.
This is true in particular for interfaces, as their properties are possibly merged into the consuming class (cf. <a href="#_implementation-of-members">Implementation of Members</a>).</p>
</div>
<div class="paragraph">
<p>The following member access modifiers are supported by N4JS:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xtext" data-lang="xtext">enum MemberAccessModifier: private
| project
| protected
| public;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The modifiers <code>protected</code> and <code>public</code> may be annotated with <code>@Internal</code>.
Thus, we can define the following set of member access modifiers:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mi>M</mi><mi>A</mi><mi>M</mi><mo>=</mo><mrow><mo>{</mo><mspace width="3.0mm"/></mrow></mtd></mtr><mtr><mtd><mstyle mathvariant="monospace"><mtext>private</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>protected@Internal</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>protected</mtext></mstyle><mo>,</mo></mtd></mtr><mtr><mtd><mstyle mathvariant="monospace"><mtext>project</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>public@Internal</mtext></mstyle><mo>,</mo><mstyle mathvariant="monospace"><mtext>public</mtext></mstyle></mtd></mtr><mtr><mtd><mrow><mo>}</mo></mrow></mtd></mtr></mtable></math>
</div>
</div>
<div class="paragraph">
<p><code>protected@Internal</code> and <code>public@Internal</code> are synthesized tags and were introduced as shorthand notation for the <code>@Internal</code> annotation together with <code>protected</code> or <code>public</code> access modifiers.
The <code>project</code> modifier is the default one and it can be omitted.
As with the type access modifiers, not all member access modifiers are available in N4JS.
Instead, they are synthesized from different construct as shown in the next example.</p>
</div>
<div class="exampleblock">
<div class="title">Example 2. Synthesized Member Access Modifiers in N4JS</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">export @Internal public class C {
private f0; // private
f1; // project
project f2; // project
@Internal protected f3; // protected@Internal
protected f4; // protected
@Internal public f5; // public@Internal
public f6; // public
private m0() {} // private
m1() {} // project
project m2() {} // project
@Internal protected m3() {} // protected@Internal
protected m4() {} // protected
@Internal public m5() {} // public@Internal
public m6() {} // public
}</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p><code>MAM</code> does not define a totally ordered set. However, its subset</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mi>M</mi><mi>A</mi><mi>M</mi><mo>\</mo><mfenced close="}" open="{"><mstyle mathvariant="monospace"><mtext>public@Internal</mtext></mstyle></mfenced></math>
</div>
</div>
<div class="paragraph">
<p>is a totally ordered set <sup class="footnote">[<a id="_footnoteref_5" class="footnote" href="#_footnote_5" title="View footnote.">5</a>]</sup> :</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mstyle mathvariant="monospace"><mtext>private</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>project</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>protected@Internal</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>protected</mtext></mstyle><mo>&lt;</mo><mstyle mathvariant="monospace"><mtext>public</mtext></mstyle></math>
</div>
</div>
<div class="paragraph">
<p><a href="#tab:Member-Access-Controls">Member Access Control</a> shows which members are accessible from where.</p>
</div>
<table id="tab:Member-Access-Controls" class="tableblock frame-all grid-all spread">
<caption class="title">Table 2. Member Access Control</caption>
<colgroup>
<col style="width: 25%;">
<col style="width: 12.5%;">
<col style="width: 12.5%;">
<col style="width: 12.5%;">
<col style="width: 12.5%;">
<col style="width: 12.5%;">
<col style="width: 12.5%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Access Modifier</th>
<th class="tableblock halign-center valign-top">Inside Module</th>
<th class="tableblock halign-center valign-top">Inside Project</th>
<th class="tableblock halign-center valign-top">Vendor</th>
<th class="tableblock halign-center valign-top">Vendor Subtypes</th>
<th class="tableblock halign-center valign-top">Other Projects</th>
<th class="tableblock halign-center valign-top">Everywhere</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>private</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>project</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>protected@Internal</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>protected</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>public@Internal</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">no</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>public</code></p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
<td class="tableblock halign-center valign-top"><p class="tableblock">yes</p></td>
</tr>
</tbody>
</table>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="type_and_member_accessibility_relation"></a><strong>Definition:</strong> <a href="#type_and_member_accessibility_relation">Type and Member Accessibility Relation</a></p>
</div>
<div class="paragraph">
<p>We define the relation</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mo>=</mo><mspace width="1.0em"/><mi>:</mi><mspace width="1.0em"/><mi>T</mi><mi>A</mi><mi>M</mi><mo>×</mo><mi>M</mi><mi>A</mi><mi>M</mi></math>
</div>
</div>
<div class="paragraph">
<p>as follows:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mtable><mtr><mtd><mo>=</mo><mspace width="1.0em"/><mi>:</mi><mi>:</mi><mo>=</mo><mrow><mo>{</mo></mrow></mtd><mtd><mfenced close=")" open="("><mstyle mathvariant="monospace"><mtext>private</mtext></mstyle><mstyle mathvariant="monospace"><mtext>private</mtext></mstyle></mfenced><mo>,</mo><mfenced close=")" open="("><mstyle mathvariant="monospace"><mtext>project</mtext></mstyle><mstyle mathvariant="monospace"><mtext>project</mtext></mstyle></mfenced><mo>,</mo></mtd></mtr><mtr><mtd/><mtd><mrow><mfenced close=")" open="("><mstyle mathvariant="monospace"><mtext>public@Internal</mtext></mstyle><mstyle mathvariant="monospace"><mtext>public@Internal</mtext></mstyle></mfenced><mo>,</mo><mfenced close=")" open="("><mstyle mathvariant="monospace"><mtext>public</mtext></mstyle><mstyle mathvariant="monospace"><mtext>public</mtext></mstyle></mfenced><mo>}</mo></mrow></mtd></mtr></mtable></math>
</div>
</div>
<div class="paragraph">
<p>We further define the relation <math xmlns="http://www.w3.org/1998/Math/MathML"><mo></mo><mi>:</mi><mi>T</mi><mi>A</mi><mi>M</mi><mo>×</mo><mi>M</mi><mi>A</mi><mi>M</mi></math> as follows:</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mfrac><mrow><mo></mo><mi>m</mi><mi>a</mi><msup><mi>m</mi><mi>'</mi></msup><mo></mo><mi>M</mi><mi>A</mi><mi>M</mi><mi>:</mi><mi>t</mi><mi>a</mi><mi>m</mi><mo>=</mo><mi>m</mi><mi>a</mi><msup><mi>m</mi><mi>'</mi></msup><mo></mo><mi>m</mi><mi>a</mi><msup><mi>m</mi><mi>'</mi></msup><mo></mo><mi>m</mi><mi>a</mi><mi>m</mi></mrow><mrow><mi>t</mi><mi>a</mi><mi>m</mi><mo></mo><mi>m</mi><mi>a</mi><mi>m</mi></mrow></mfrac></math>
</div>
</div>
<div class="paragraph">
<p>Less, greater then etc. are defined accordingly.</p>
</div>
</div>
</div>
<div class="openblock definition">
<div class="content">
<div class="paragraph">
<p><a id="member_accessibility"></a><strong>Definition:</strong> <a href="#member_accessibility">Member Accessibility</a></p>
</div>
<div class="paragraph">
<p>The function</p>
</div>
<div class="openblock">
<div class="content">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><msub><mi>α</mi><mi>m</mi></msub><mi>:</mi><mi>M</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>R</mi><mi>e</mi><mi>f</mi><mi>e</mi><mi>r</mi><mi>e</mi><mi>n</mi><mi>c</mi><mi>e</mi><mo>×</mo><mi>M</mi><mi>e</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mi>D</mi><mi>e</mi><mi>c</mi><mi>l</mi><mi>a</mi><mi>r</mi><mi>a</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo></mo><mi>B</mi><mi>o</mi><mi>o</mi><mi>l</mi><mi>e</mi><mi>a</mi><mi>n</mi></math>
</div>
</div>
<div class="paragraph">
<p>computes if a given reference can access the member declaration that it
references.</p>
</div>
</div>
</div>
<div class="paragraph">
<p>Note that <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>α</mi><mi>m</mi></msub></math> and <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>b</mi><mi>i</mi><mi>n</mi><mi>d</mi></math> are different functions.
A reference can only bind to a declaration if it can access the declaration.
However, bind requires more condition to work (correct metatypes, no shadowing etc).</p>
</div>
<div class="paragraph">
<p>Formally, we define <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>α</mi><mi>m</mi></msub></math> for a given reference <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>r</mi></math> and member declaration <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>M</mi></math> as follows: <sup class="footnote">[<a id="_footnoteref_6" class="footnote" href="#_footnote_6" title="View footnote.">6</a>]</sup> <sup class="footnote">[<a id="_footnoteref_7" class="footnote" href="#_footnote_7" title="View footnote.">7</a>]</sup></p>
</div>
<div class="paragraph">
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>M</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>public</mtext></mstyle></mrow><mrow><msub><mi>α</mi><mi>m</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>M</mi></mfenced></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>r</mi><mo>.</mo><mi>v</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>o</mi><mi>r</mi><mo>=</mo><mi>M</mi><mo>.</mo><mi>v</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>o</mi><mi>r</mi><mspace width="3.0mm"/><mi>M</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>public@Internal</mtext></mstyle></mrow><mrow><msub><mi>α</mi><mi>m</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>M</mi></mfenced></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>r</mi><mo>.</mo><mi>o</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>r</mi><mo></mo><mi>r</mi><mo>.</mo><mi>r</mi><mi>e</mi><mi>c</mi><mi>e</mi><mi>i</mi><mi>v</mi><mi>e</mi><mi>r</mi><mo>.</mo><mi>s</mi><mi>u</mi><mi>p</mi><mi>e</mi><msup><mi>r</mi><mo>*</mo></msup><mspace width="3.0mm"/><mi>M</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>protected</mtext></mstyle></mrow><mrow><msub><mi>α</mi><mi>m</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>M</mi></mfenced></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>r</mi><mo>.</mo><mi>o</mi><mi>w</mi><mi>n</mi><mi>e</mi><mi>r</mi><mo></mo><mi>r</mi><mo>.</mo><mi>r</mi><mi>e</mi><mi>c</mi><mi>e</mi><mi>i</mi><mi>v</mi><mi>e</mi><mi>r</mi><mo>.</mo><mi>s</mi><mi>u</mi><mi>p</mi><mi>e</mi><msup><mi>r</mi><mo>*</mo></msup><mspace width="3.0mm"/><mi>r</mi><mo>.</mo><mi>v</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>o</mi><mi>r</mi><mo>=</mo><mi>M</mi><mo>.</mo><mi>v</mi><mi>e</mi><mi>n</mi><mi>d</mi><mi>o</mi><mi>r</mi><mspace width="3.0mm"/><mi>M</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>protected@Internal</mtext></mstyle></mrow><mrow><msub><mi>α</mi><mi>m</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>M</mi></mfenced></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>r</mi><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>j</mi><mi>e</mi><mi>c</mi><mi>t</mi><mo>=</mo><mi>M</mi><mo>.</mo><mi>p</mi><mi>r</mi><mi>o</mi><mi>j</mi><mi>e</mi><mi>c</mi><mi>t</mi><mspace width="3.0mm"/><mi>M</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>project</mtext></mstyle></mrow><mrow><msub><mi>α</mi><mi>m</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>M</mi></mfenced></mrow></mfrac></math><br>
<math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mrow><mi>r</mi><mo>.</mo><mi>m</mi><mi>o</mi><mi>d</mi><mi>u</mi><mi>l</mi><mi>e</mi><mo>=</mo><mi>r</mi><mo>.</mo><mi>m</mi><mi>o</mi><mi>d</mi><mi>u</mi><mi>l</mi><mi>e</mi><mspace width="3.0mm"/><mi>M</mi><mo>.</mo><mi>a</mi><mi>c</mi><mi>c</mi><mo>=</mo><mstyle mathvariant="monospace"><mtext>private</mtext></mstyle></mrow><mrow><msub><mi>α</mi><mi>m</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>M</mi></mfenced></mrow></mfrac></math></p>
</div>
<div class="paragraph">
<p>If the type of the arguments is clear from the context, we simply write <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>α</mi><mfenced close=")" open="("><mi>r</mi><mi>M</mi></mfenced></math> instead of <math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mi>α</mi><mi>m</mi></msub><mfenced close=")" open="("><mi>r</mi><mi>M</mi></mfenced></math>.</p>
</div>
<div class="paragraph">
<p>Although private members are accessible inside a module, it is not possible to redefine (override etc.) these members (see <a href="#_redefinition-of-members">Redefinition of Members</a>).</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-4"></a><strong>Req. IDE-4:</strong> <a href="#Req-IDE-4">Default Member Access Modifiers</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>The following constraints for member access modifiers must hold:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>The <em>default modifier</em> for members of user-declared classes is <code>project</code>.</p>
</li>
<li>
<p>The <em>default modifier</em> for members of interfaces is the same as the visibility of the interface itself, except for private interfaces.
For private interfaces, the default modifier for members is <code>project</code>.</p>
</li>
<li>
<p>The modifier for enum literals is always <code>public</code>.</p>
</li>
<li>
<p>Private members of a classifier are visible and accessible within a module, i.e. you can access the private method of a class, for instance,
when the use of the class as receiver is in the same module where the class has been defined.
In case of inheritance, private members are visible if the host (e.g. the class) is in the same module as the provider (the extended class).
This also means that abstract members of a class are allowed to be defined private as they may be overridden within a module.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="exampleblock">
<div class="title">Example 3. Type and Member Access Modifiers</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">export project interface I {
project foo();
}
// This interface may be used publicly, but since the inherited method foo() is project visible only,
// it is not possible to implement that interface in other projects.
export public interface J extends I {
}
// Since the visibility of foo is set to public here, it is possible to implement this interface in other projects.
export public interface K extends I {
@Override public foo();
}
// Since foo is private, it is not possible to subclass the class in other modules. Still, it
// is possible to use it in other projects.
// XPECT noerrors --&gt;
export public abstract class C {
private abstract foo();
public static C instance() {
// return some default instance
...
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>As demonstrated in the following snippet, class <code>C</code> can be used but not subclassed in other modules:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import C from "C"
// XPECT errors --&gt; "Cannot extend class C: cannot implement one or more non-accessible abstract members: method C.foo." at "C"
export public abstract class Sub extends C {
}
// XPECT noerrors --&gt;
var c: C = C.instance();</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>Members of non-visible types are, in general, not visible for a client.
Members may become visible, however, if they are accessed via a visible type which inherits these members.
The following examples demonstrate two different scenarios:</p>
</div>
<div class="exampleblock">
<div class="title">Example 4. Declaring type vs receiver type</div>
<div class="content">
<div class="paragraph">
<p>It is especially noteworthy that the declaring type of a member is
generally not considered for the accessibility of that member but only
the receiver type is relevant.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class Base {
public m(b: Base): void {}
}
export public class ApiType extends Base {
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import * as N from "Base";
var t = new N.ApiType();
// member can be accessed although type Base is not exported:
t.m(t);</code></pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>The property access to the member <code>m</code> is valid because it fulfills the constraints for accessibility.
The receiver of the property access is <code>t</code> of type <code>ApiType</code>.
That type is exported and accessible.
Therefore, the inherited member <code>m</code> is also considered valid since it is also defined <code>public</code>.</p>
</div>
<div class="paragraph">
<p>This rule allows for defining a common functionality in module or project visible types that becomes accessible via exported, visible subtypes.</p>
</div>
<div class="exampleblock">
<div class="title">Example 5. Member Access and Type Access Interplay</div>
<div class="content">
<div class="paragraph">
<p>The following example demonstrates the behavior when
non-visible types are used as return types. In this case, all the
members of the non-visible types are not accessible, even if they have a
public access modifier.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">class A {
foo(): void{}
}
export public class C {
public getHidden(): A { return new A() };
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-n4js" data-lang="n4js">import * as Nfrom "A"
class Client {
f(): void {
var c = new N.C();
// XPECT noerrors --&gt; Getting an instance the hidden type is possible
var hidden = c.getHidden();
// XPECT errors --&gt; "The method foo is not visible." at "foo"
hidden.foo();
}
}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_valid-names"><a class="anchor" href="#_valid-names"></a><a class="link" href="#_valid-names">3.2.2. Valid Names</a></h4>
<div class="paragraph">
<p>For identifier and property names, the same constraints as in ECMAScript
[<a href="#ECMA11a">ECMA11a(p.S7.6)</a>]
[<a href="#ECMA11a">ECMA11a(p.S7.6.1.2)</a>]
[<a href="#ECMA11a">ECMA11a(p.S11.6)</a>] are applied.</p>
</div>
<div class="paragraph">
<p>Identifier names in N4JS are defined similar to [<a href="#ECMA11a">ECMA11a(p.S11.6)</a>], making it possible to even use reserved words (keywords etc.).
For some element types, errors or warnings are issued in order to prevent problems when using these names.</p>
</div>
<div class="openblock requirement">
<div class="content">
<div class="paragraph">
<p><a id="Req-IDE-5"></a><strong>Req. IDE-5:</strong> <a href="#Req-IDE-5">Forbidden Identifier Names in N4JS</a> (ver. 1)</p>
</div>
<div class="paragraph">
<p>In N4JS mode, errors are generated in the following cases:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>A name of a type equals</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>an access modifier</p>
</li>
<li>
<p><code>set</code> or <code>get</code></p>
</li>
<li>
<p>an ECMAScript keyword</p>
</li>
<li>
<p>a boolean literal</p>
</li>
<li>
<p>the name of a base type</p>
</li>
</ol>
</div>
</li>
<li>
<p>The name of a function or function expression equals (but not the method)</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">