Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Язык · 5 глав · 14 правил

    Выражения и операторы

    Defines expression formation, grouping, and operator behavior.

    Scope and ownership

    Ссылка

    This page owns expression grouping, operators, ranges, and member and index access.

    It also specifies the retirement of pipeline, composition, and expression-placeholder syntax. Functions and generics owns call argument binding. Collections and comprehensions owns collection construction. Type and library entries own individual members. Pattern matching owns wildcard patterns. Failure and propagation owns postfix ? behavior.

    Selected source forms

    Ссылка
    EBNF
    1. Grouped = "(" Expression ")" ;
    2. Unary = ("-" | "!") Unary | Power ;
    3. Power = Postfix ["**" Unary] ;
    4. RangeShape = Additive (".." | "..<") Additive ["by" Additive] ;
    5. IndexSuffix = "[" Expression "]" ;
    6. MemberSuffix = "." MemberName ;
    7. OptionalMemberSuffix = "?." MemberName ;

    This handwritten excerpt shows selected source forms. The precedence record supplies the grouping between operator families. It omits call argument lists, collection construction, and other page-owned syntax; parsing alone does not establish operand legality.

    Правилоtopaz.rule.expressions-and-operators.grouping

    Grouping and postfix forms

    Empty parentheses form the unit literal (). Parentheses around one expression explicitly group that expression. A parenthesized comma list is rejected during parsing with TPZ2001. Postfix extensions attach to the preceding expression in source order.

    Parentheses select a grouping for an expression. The unit literal () is documented in Literals and templates. Function argument binding, collection construction, propagation, and nominal updates keep their own owners; their suffixes appear here only to locate their grouping.

    Причина

    Explicit grouping makes operand relationships visible. An ordered postfix chain gives each extension one receiver.

    Правилоtopaz.rule.expressions-and-operators.control-operands

    Explicit control operands

    A control operand has a required outer pair of parentheses. The construct consumes that pair and parses its contents with the ordinary expression grammar. Record construction, record update, and lambdas keep the same forms they have in a binding or call argument. Their result types are checked separately.

    PositionCanonical form
    if testif (test) { body }
    if-let valueif let Pattern = (value) { body }
    while testwhile (test) { body }
    while-let valuewhile let Pattern = (value) { body }
    for iterablefor Pattern in (iterable) { body }
    using valueusing name = (value) { body }
    match scrutineematch (value) { cases }
    match guardcase Pattern if (test) => body
    comprehension iterable[for Pattern in (iterable) => value]
    comprehension filter[for Pattern in (iterable) if (test) => value]

    Omitting the required pair is rejected during parsing with TPZ2001. Extra parentheses inside the pair retain ordinary grouping. The existing concurrent(timeout: expression) argument list already delimits its timeout expression. A loop has no operand.

    Причина

    An undelimited input and the same input inside the required parentheses supply the same condition, matched value, iteration source, or resource. The boundary preserves that intent and lets each position use ordinary expression grammar. Record construction and updates retain their existing forms, and lambdas retain one parenthesized parameter list. Parentheses inside an operand group that expression. The explicit boundary prevents a record body or a lambda arrow from taking the place of the following control body or case arrow.

    Precedence and associativity

    Ссылка
    Правилоtopaz.rule.expressions-and-operators.precedence

    Precedence and associativity

    Higher rows bind more tightly. These rows specify parser grouping. Operand-type acceptance is checked separately.

    RankFormsAssociationBinary parser level
    1call suffix, index suffix, member suffix, optional-member suffix, propagation suffix, record-update suffixSuccessive postfix extensionsSeparate parser production
    2**RightSeparate parser production
    3prefix -, !Recursive prefixSeparate parser production
    4*, /, %Left9
    5+, -Left8
    6.., ..<Left7
    7==, !=, <, <=, >, >=, inLeft6
    8&&Left5
    9\|\|Left4
    10??Left3

    A prefix on the left applies outside power. The right operand of ** admits unary syntax. The range row accepts the by step clause.

    ExpressionGrouping
    -2 ** 2-(2 ** 2)
    2 ** 3 ** 22 ** (3 ** 2)
    a ?? b ?? c(a ?? b) ?? c

    The structured table describes grouping. A parsed combination can still fail type checking. Equality, ordering, and in share one level, and ?? groups to the left.

    Power accepts a unary expression on its right. Thus -2 ** 2 groups as -(2 ** 2), while 2 ** -1 parses with a negative exponent. The integer exponent restriction is a separate runtime condition.

    Причина

    A fixed precedence table makes expression grouping independent of whitespace. The same grouping applies before operand types are checked.

    Unary, binary, and logical operators

    Ссылка
    Правилоtopaz.rule.expressions-and-operators.unary

    Unary operators

    OperatorsOperand typesResultOperation
    !boolboolLogical negation
    -int, float, BigInt, DecimalOperand type- negates the value

    Prefix + is rejected during parsing with TPZ2001. Use the operand directly. Binary + remains addition.

    Literal sign rules are defined by Literals and templates. Other operand families remain Pending.

    Literal bounds are covered by Literals and templates. This rule covers operators applied to values. Unary minus negates a value and does not introduce another numeric type.

    Причина

    An ordinary expression already denotes its value, so an identity prefix would add another spelling. Numeric negation preserves the operand type.

    Правилоtopaz.rule.expressions-and-operators.arithmetic

    Arithmetic operands and results

    The following operand pairs produce the listed result types.

    OperatorsLeft operandRight operandResultOperation
    +, -, *, /, **intintintArithmetic
    +, -, *, /, **floatfloatfloatArithmetic
    %intintintArithmetic
    +stringstringstringConcatenation
    +, -, *BigIntBigIntBigIntArithmetic
    +, -, *DecimalDecimalDecimalArithmetic

    Mixed int/float operands are rejected during checking. Integer and Length value boundaries are specified below.

    Arithmetic examples use small integers so grouping is visible independently of overflow boundaries. BigInt and Decimal division APIs belong to their library entries. The Types and Literals pages own type forms, literal bounds, and units.

    The Decimal value contract defines exact decimal arithmetic and canonical scale. Explicit BigInt division and remainder follow the BigInt contract. Duration arithmetic and range failures follow the Duration value rule.

    Evaluation follows the operand and assignment order.

    Причина

    Requiring matching numeric types avoids implicit changes in precision. Explicit result types let arithmetic participate in the same type checks as other expressions.

    Правилоtopaz.rule.expressions-and-operators.numeric-boundaries

    Integer and Length value boundaries

    Integer arithmetic stays within -9223372036854775808 through 9223372036854775807. Division truncates toward zero. A nonzero remainder has the dividend's sign. Integer 0 ** 0 is 1.

    BoundaryRuntime diagnostic
    Integer or Length division by zero, or integer remainder by zeroTPZ4002
    Integer overflow, including minimum int divided or reduced modulo -1TPZ4004
    Integer power with a negative exponentTPZ4005
    Integer exponent greater than 4294967295, even with base 0 or 1TPZ4004
    Unrepresentable Length result or a non-finite scaling operandTPZ4004

    Length operations use the following operand pairs. U denotes the same unit on both Length operands. Mixed units are rejected during checking.

    OperatorsLeftRightResult
    +, -Length<U>Length<U>Length<U>
    /Length<U>Length<U>float
    *Length<U>int-or-floatLength<U>
    *int-or-floatLength<U>Length<U>
    /Length<U>intLength<U>

    Length multiplication and integer division round to the nearest representable fixed-precision value, with ties choosing the even value. Dividing two Length values gives their floating-point ratio.

    When a constant initializer reaches a numeric fault, checking rejects it with TPZ5001 and a message beginning constant expression error:.

    The physical length contract defines stored scaled points and explicit unit conversions.

    Причина

    Checked arithmetic prevents silent wraparound in computed sizes. Matching length units prevents accidental mixing of document measurements. Ties-to-even rounding avoids a consistent bias at exact halfway values.

    Правилоtopaz.rule.expressions-and-operators.comparison-membership

    Comparison and membership

    ==, != compare equality, and <, <=, >, >= compare order. The operands must have compatible, comparable types. These operations produce bool. Comparison capabilities are defined by Protocols and implementations. A declared nominal Eq or Order conformance supplies both its protocol-qualified method and the corresponding operators. Nested derived comparisons use that same conformance.

    Write element membership as element in container. in produces bool for Array<T>, Set<T>, Range<int>. The value must be compatible with the container's element type. Range membership requires both bounds and step alignment. Map, string are rejected as membership containers during checking.

    Substring search and Map key lookup follow their distinct library contracts.

    The comparison operators produce Boolean results after the relevant type and capability checks. General compatibility and protocol resolution are documented by Types and Protocols and implementations. For a range, membership also considers its step.

    The Decimal comparison contract defines exact equality and ordering independently of input padding.

    Причина

    Set.contains and in ask the same question about whether an equal element belongs to a set. The in operator expresses that membership intent for arrays, sets, and integer ranges. Range membership includes step alignment so it agrees with iteration. Substring search and Map key lookup retain their distinct input and result contracts.

    Правилоtopaz.rule.expressions-and-operators.short-circuit

    Logical operators and coalescing

    The left operand is evaluated first. The following cases skip the right operand and produce the indicated value. Otherwise, the right operand is evaluated and supplies the result.

    OperatorLeft typeRight typeSkip right when left isResult when skippedEvaluate right when left is
    &&boolboolfalsefalsetrue
    \|\|boolbooltruetruefalse
    ??Option<T>TSome(value)valueNone()
    ??T \| nullTnon-nullleftnull

    The short-circuit decision follows evaluation of the left operand. In the example, any call to mark would print an extra line; that line is absent from the independent expected output.

    Причина

    Skipping an unused operand avoids its effects and failures. This lets a guard or fallback depend on the value already computed.

    Derived equality and operators use the inner manual equality

    Ссылка
    example.tpzDerived equality and operators use the inner manual equality
    1. import std.io { writeLine }
    2. record Token { key: int, noise: int }
    3. impl Eq<Token> {
    4. function equals(a: Token, b: Token) -> bool { a.key == b.key }
    5. }
    6. record Box derives Eq { item: Token }
    7. let a = Box { item: Token { key: 1, noise: 10 } }
    8. let b = Box { item: Token { key: 1, noise: 20 } }
    9. let c = Box { item: Token { key: 2, noise: 10 } }
    10. writeLine("{Eq.equals(a, b)}")
    11. writeLine("{a == b}")
    12. writeLine("{Eq.equals(a, c)}")
    13. writeLine("{a != c}")
    Ожидаемый выводКод завершения 0
    true
    true
    false
    true
    
    $ topaz run example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. true
    2. true
    3. false
    4. true

    A manual equality hides an opaque field from outer operators

    Ссылка
    example.tpzA manual equality hides an opaque field from outer operators
    1. import std.io { writeLine }
    2. record Callback { key: int, run: () -> int }
    3. impl Eq<Callback> {
    4. function equals(a: Callback, b: Callback) -> bool { a.key == b.key }
    5. }
    6. record Box derives Eq { item: Callback }
    7. let a = Box { item: Callback { key: 1, run: () => 7 } }
    8. let b = Box { item: Callback { key: 1, run: () => 9 } }
    9. writeLine("{a == b}")
    10. writeLine("{Eq.equals(a, b)}")
    Ожидаемый выводКод завершения 0
    true
    true
    
    $ topaz run example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. true
    2. true

    Derived ordering and operators use the inner manual ordering

    Ссылка
    example.tpzDerived ordering and operators use the inner manual ordering
    1. import std.io { writeLine }
    2. record Rank { score: int }
    3. impl Order<Rank> {
    4. function compare(a: Rank, b: Rank) -> int {
    5. if (a.score > b.score) { -1 } else if (a.score < b.score) { 1 } else { 0 }
    6. }
    7. }
    8. record Box derives Order { item: Rank }
    9. let a = Box { item: Rank { score: 9 } }
    10. let b = Box { item: Rank { score: 3 } }
    11. writeLine("{Order.compare(a, b)}")
    12. writeLine("{a < b}")
    13. writeLine("{Order.compare(b, a)}")
    14. writeLine("{b > a}")
    Ожидаемый выводКод завершения 0
    -1
    true
    1
    true
    
    $ topaz run example.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. -1
    2. true
    3. 1
    4. true
    Правилоtopaz.rule.expressions-and-operators.evaluation-order

    Operand and assignment evaluation order

    Binary expressions evaluate their operands from left to right. The same order applies within nested operands. The first runtime fault terminates evaluation, so later operands do not run. The short-circuit rule still determines whether a right operand runs.

    Assignment formEvaluation order
    x = value()Evaluate the right value, then write x.
    a[index()] = value()Evaluate the receiver, evaluate the index, validate the slot, evaluate the right value, then write the slot.
    record.field = value()Evaluate the right value, then read the named record root, update the field, and write the root.
    a[index()].field = value()Evaluate the receiver and index, validate the slot, evaluate the right value, then read the record, update the field, and write the slot.
    x += value() and other compound arithmetic assignmentsEvaluate the target and read its old value, evaluate the right value, apply the operation, then write the result.

    A fault in an earlier assignment step prevents later steps. Assignment does not give a named record field a read before its right-hand value.

    The short-circuit rule determines which operands run. Function calls keep their argument evaluation order.

    Причина

    One operand order makes effects and the first fault reproducible. Existing assignment forms retain their evaluation order.

    Ranges and access

    Ссылка
    Правилоtopaz.rule.expressions-and-operators.range

    Ranges and steps

    Both endpoints are required and have type int. The result has type Range<int>.

    OperatorUpper bound
    ..inclusive
    ..<exclusive

    The by clause supplies an int step. Its default is 1. The sequence begins at the first endpoint and advances by adding the step. A positive step advances toward an increasing end value. A negative step advances toward a decreasing end value. Bounds in the wrong direction produce an empty range.

    Membership requires bounds and step alignment. A zero step is invalid. A statically detected zero step is rejected during checking. A zero step that reaches evaluation causes a runtime fault. Iteration is defined by Blocks and control flow.

    The by clause is part of the range expression. An inclusive upper bound is included only if the sequence reaches it. Blocks and control flow describes how for consumes a range; collection construction is documented separately.

    Причина

    Explicit bounds and steps define the visited integers without materializing an array. Membership and iteration use the same sequence.

    Правилоtopaz.rule.expressions-and-operators.access

    Member, index, and optional access

    object.member follows the selected type or library entry's member contract. array[index] accepts an int index into Array<T> and produces T. Indices start at 0. Other index types are rejected during checking. Negative or out-of-bounds indices cause a runtime fault.

    object?.member accepts Option<T>, T | null.

    ReceiverMember access and result
    None()Skip access and produce None()
    nullSkip access and produce null
    Some(value)Access the wrapped value and produce one Option layer, flattening an existing Option result
    non-null TAccess the value and produce the member result
    Receiver typeResult type
    Option<T>Option<member-type> with one-layer flattening
    T \| nullmember-type \| null

    A member name selects a field or member whose individual contract belongs to its type or library entry. The access example uses an existing array's length property only to show optional access. Array construction, mutation, and the property's API contract are outside this page.

    Evaluation follows the operand and assignment order.

    Причина

    Optional access skips a member lookup when its receiver is absent. Bounds checks prevent an invalid array position from producing an ordinary element value.

    Правилоtopaz.rule.expressions-and-operators.string-text-units

    Choose Unicode scalars or grapheme clusters explicitly

    text.scalars() returns Array<string> in source order. Each element contains one Unicode scalar value. Empty text returns an empty array. The operation preserves the stored scalars without normalization. Joining its elements with an empty separator reproduces the original string.

    text.graphemes() follows the Unicode grapheme contract. Use the returned array's length and indexing operations for the chosen text unit.

    Loop inputs follow the iteration rule. Choose scalar values or grapheme clusters explicitly before iterating over text.

    Причина

    A scalar and a grapheme cluster are different text units. Explicit names preserve scalar algorithms while allowing document editing to keep combining marks, Hangul syllables, and emoji sequences together. Unicode 16 matches the language character data and gives every host the same boundaries. Returning an Array reuses its count and index operations without additional string spellings.

    Calls and function composition

    Ссылка
    Правилоtopaz.rule.expressions-and-operators.pipeline

    Ordinary calls and saved values

    Write calls as callee(arguments) and members as value.member. Bind an intermediate value with let when it must be evaluated once or reused.

    Method chains and successive let bindings read from the input through its transformations in order.

    |> is rejected during parsing with TPZ2001. This includes bare-callable, inserted-argument, placeholder, and member-shortcut stages. A standalone expression _ is also rejected during parsing.

    When migrating a pipeline with effects, bind the input first, then evaluate the callee and written arguments in their required order. The resulting ordinary call follows Functions and generics.

    Use a named binding when one computed value is needed more than once. A wildcard _ belongs to a pattern and has no expression meaning. Ordinary calls use the argument binding rules in Functions and generics.

    Причина

    A pipeline and a method chain both present a value followed by the transformations that consume it. When the transformations are ordinary functions, successive let bindings present the same input-to-result reading order. These forms preserve the intended data flow and make evaluation and reuse explicit. Written call arguments keep each consumed value visible. Bind effectful input, callee, and argument expressions in their required order when replacing a pipeline.

    Правилоtopaz.rule.expressions-and-operators.composition

    Compose calls in a function body

    Compose calls in a function body, for example (value: T) => second(first(value)). Input, intermediate, and result types follow ordinary function and call rules.

    The body can name successive results with let in data-flow order.

    The >> composition operator is rejected during parsing with TPZ2001. Bind function values before constructing the lambda when their evaluation or capture must happen once.

    To preserve composition-time evaluation, first bind each function value once and in the desired order. Capture those immutable bindings in the function body. Later calls then reuse the same function values.

    Причина

    A composition operator and a function body both describe a transformation whose result becomes the next transformation input. Successive let bindings inside the body read in that same data-flow order, and ordinary call typing preserves the intermediate types. Binding function values before constructing the body preserves evaluation and capture that must happen once.

    Examples and expected results

    Ссылка

    Each example is a complete source file with an independent expected result and an assertion plan. No execution receipt is attached. Missing boundary coverage remains explicit; a future observation that differs from an intended result requires triage and an implementation limitation when appropriate, rather than replacement of the expectation.

    Grouping arithmetic and power

    Ссылка
    example.tpzGrouping arithmetic and powerОткрыть песочницу →
    1. import std.io
    2. io.writeLine("{2 + 3 * 4}")
    3. io.writeLine("{(2 + 3) * 4}")
    4. io.writeLine("{20 - 5 - 3}")
    5. io.writeLine("{2 ** 3 ** 2}")
    6. io.writeLine("{-2 ** 2}")
    7. io.writeLine("{(-2) ** 2}")
    Зафиксированный выводКод завершения 0
    14
    20
    12
    512
    -4
    4
    
    $ topaz run example.tpz --compiler self · Зафиксировано с Топазом 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 14
    2. 20
    3. 12
    4. 512
    5. -4
    6. 4
    Наблюдаемые утверждения · Пройдено · 5.21.3

    Код завершения 0.

    Наблюдаемый стандартный вывод
    1. 14
    2. 20
    3. 12
    4. 512
    5. -4
    6. 4

    Нет вывода ошибок.

    • Пройдено · expected 0; observed 0
    • Пройдено · stdout matches the authored expectation
    • Пройдено · stderr matches the authored expectation
    • Пройдено · stdout matches the authored expectation
    • Пройдено · stdout matches the authored expectation

    The expected result is specified from the source contract. This exact fixture has not been run on a public Topaz 5.21.x CLI.

    Skipping a right operand

    Ссылка
    example.tpzSkipping a right operandОткрыть песочницу →
    1. import std.io
    2. function mark() -> bool {
    3. io.writeLine("evaluated")
    4. true
    5. }
    6. io.writeLine("{false && mark()}")
    7. io.writeLine("{true || mark()}")
    8. let present: Option<int> = Some(7)
    9. let absent: Option<int> = None()
    10. io.writeLine("{present ?? 9}")
    11. io.writeLine("{absent ?? 9}")
    Зафиксированный выводКод завершения 0
    false
    true
    7
    9
    
    $ topaz run example.tpz --compiler self · Зафиксировано с Топазом 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. false
    2. true
    3. 7
    4. 9
    Наблюдаемые утверждения · Пройдено · 5.21.3

    Код завершения 0.

    Наблюдаемый стандартный вывод
    1. false
    2. true
    3. 7
    4. 9

    Нет вывода ошибок.

    • Пройдено · expected 0; observed 0
    • Пройдено · stdout matches the authored expectation
    • Пройдено · stderr matches the authored expectation

    The expected result is specified from the source contract. This exact fixture has not been run on a public Topaz 5.21.x CLI.

    Apply ordinary calls and a function body

    Ссылка
    example.tpzApply ordinary calls and a function bodyОткрыть песочницу →
    1. import std.io
    2. function increment(n: int) -> int { n + 1 }
    3. function double(n: int) -> int { n * 2 }
    4. function subtract(a: int, b: int) -> int { a - b }
    5. let composed = (n: int) => double(increment(n))
    6. io.writeLine("{double(increment(3))}")
    7. io.writeLine("{composed(3)}")
    8. io.writeLine("{subtract(10, 3)}")
    9. io.writeLine("{subtract(3, 10)}")
    Ожидаемый выводКод завершения 0
    8
    8
    7
    -7
    
    $ topaz run example.tpz --compiler self
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 8
    2. 8
    3. 7
    4. -7

    This fixture uses ordinary calls and a lambda. Its expected values are unchanged. Product execution of this revised fixture remains pending.

    Membership respects a range's step

    Ссылка
    example.tpzMembership respects a range's stepОткрыть песочницу →
    1. import std.io
    2. let odd = 1..<6 by 2
    3. io.writeLine("{1 in odd}")
    4. io.writeLine("{2 in odd}")
    5. io.writeLine("{5 in odd}")
    6. io.writeLine("{6 in odd}")
    Зафиксированный выводКод завершения 0
    true
    false
    true
    false
    
    $ topaz run example.tpz --compiler self · Зафиксировано с Топазом 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. true
    2. false
    3. true
    4. false
    Наблюдаемые утверждения · Пройдено · 5.21.3

    Код завершения 0.

    Наблюдаемый стандартный вывод
    1. true
    2. false
    3. true
    4. false

    Нет вывода ошибок.

    • Пройдено · expected 0; observed 0
    • Пройдено · stdout matches the authored expectation
    • Пройдено · stderr matches the authored expectation
    • Пройдено · stdout matches the authored expectation

    The expected result is specified from the source contract. This exact fixture has not been run on a public Topaz 5.21.x CLI.

    Indexing and optional member access

    Ссылка
    example.tpzIndexing and optional member accessОткрыть песочницу →
    1. import std.io
    2. let values = [4, 5]
    3. let present: Option<Array<int>> = Some(values)
    4. let absent: Option<Array<int>> = None()
    5. io.writeLine("{values[0]}")
    6. io.writeLine("{present?.length ?? 0}")
    7. io.writeLine("{absent?.length ?? 0}")
    Зафиксированный выводКод завершения 0
    4
    2
    0
    
    $ topaz run example.tpz --compiler self · Зафиксировано с Топазом 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 4
    2. 2
    3. 0
    Наблюдаемые утверждения · Пройдено · 5.21.3

    Код завершения 0.

    Наблюдаемый стандартный вывод
    1. 4
    2. 2
    3. 0

    Нет вывода ошибок.

    • Пройдено · expected 0; observed 0
    • Пройдено · stdout matches the authored expectation
    • Пройдено · stderr matches the authored expectation

    The expected result is specified from the source contract. This exact fixture has not been run on a public Topaz 5.21.x CLI.

    Rejecting a parenthesized comma list

    Ссылка
    example.tpzRejecting a parenthesized comma listОткрыть песочницу →
    1. let value = (1, 2)
    Зафиксированный выводКод завершения 1
    Нет стандартного вывода.
    error[TPZ2001]: parentheses group a single expression; `(a, b)` comma lists are not Topaz syntax
     --> example.tpz:1:15
      |
    1 | let value = (1, 2)
      |               ^
    
    example.tpz: 1 diagnostic
    
    $ topaz check example.tpz --compiler self · Зафиксировано с Топазом 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      parenthesized-comma-list at example.tpz:1:15

    Наблюдаемые утверждения · Пройдено · 5.21.3

    Код завершения 1.

    Нет стандартного вывода.

    Наблюдаемый вывод ошибок
    1. error[TPZ2001]: parentheses group a single expression; `(a, b)` comma lists are not Topaz syntax
    2. --> example.tpz:1:15
    3. |
    4. 1 | let value = (1, 2)
    5. | ^
    6. example.tpz: 1 diagnostic
    • Пройдено · expected nonzero; observed 1
    • Пройдено · checking TPZ2001; cause parenthesized-comma-list; primary location asserted; additional diagnostics allow

    This fixture expects rejection at the comma because parentheses group a single expression. It is run through check so parsing is reached, and requires the parsing diagnostic and its location. The exact public CLI observation is pending.

    Signed division, zero power, and Length arithmetic

    Ссылка
    example.tpzSigned division, zero power, and Length arithmeticОткрыть песочницу →
    1. import std.io
    2. let quotient = -7 / 3
    3. let remainder = -7 % 3
    4. let zeroPower = 0 ** 0
    5. io.writeLine("{quotient} {remainder} {zeroPower}")
    6. io.writeLine("{(1pt + 2pt) == 3pt}")
    7. io.writeLine("{(1pt * 2) == 2pt}")
    8. io.writeLine("{(2 * 1pt) == 2pt}")
    9. io.writeLine("{(1pt / 2) == 0.5pt}")
    10. io.writeLine("{3pt / 2pt}")
    Ожидаемый выводКод завершения 0
    -2 -1 1
    true
    true
    true
    true
    1.5
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. -2 -1 1
    2. true
    3. true
    4. true
    5. true
    6. 1.5

    The expected result follows from current SELF source. Execution against public Topaz 5.21.3 is pending CI.

    Integer division by zero is rejected in a constant

    Ссылка
    example.tpzInteger division by zero is rejected in a constantОткрыть песочницу →
    1. const bad = 1 / 0
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    • TPZ5001 →

      constant-integer-division-zero at example.tpz:1:13

    The expected result follows from current SELF source. Execution against public Topaz 5.21.3 is pending CI.

    An overflowing integer constant is rejected

    Ссылка
    example.tpzAn overflowing integer constant is rejectedОткрыть песочницу →
    1. const bad = 9223372036854775807 + 1
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    • TPZ5001 →

      constant-integer-addition-overflow at example.tpz:1:13

    The expected result follows from current SELF source. Execution against public Topaz 5.21.3 is pending CI.

    An integer exponent must be non-negative

    Ссылка
    example.tpzAn integer exponent must be non-negativeОткрыть песочницу →
    1. const bad = 2 ** -1
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    • TPZ5001 →

      constant-integer-negative-exponent at example.tpz:1:13

    The expected result follows from current SELF source. Execution against public Topaz 5.21.3 is pending CI.

    Length division by zero is rejected in a constant

    Ссылка
    example.tpzLength division by zero is rejected in a constantОткрыть песочницу →
    1. const bad = 1pt / 0
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    • TPZ5001 →

      constant-length-division-zero at example.tpz:1:13

    The expected result follows from current SELF source. Execution against public Topaz 5.21.3 is pending CI.

    An unrepresentable Length constant is rejected

    Ссылка
    example.tpzAn unrepresentable Length constant is rejectedОткрыть песочницу →
    1. const bad = 1pt * 9223372036854775807
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    • TPZ5001 →

      constant-length-unrepresentable at example.tpz:1:13

    The expected result follows from current SELF source. Execution against public Topaz 5.21.3 is pending CI.

    Rejecting unary plus before an integer

    Ссылка
    example.tpzRejecting unary plus before an integerОткрыть песочницу →
    1. let value = +1
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz --compiler self --format json
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    Write 1 to use the integer value.

    Rejecting unary plus before a bound value

    Ссылка
    example.tpzRejecting unary plus before a bound valueОткрыть песочницу →
    1. let value = 1
    2. let copy = +value
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz --compiler self --format json
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    Use the bound value directly.

    Rejecting unary plus before a float

    Ссылка
    example.tpzRejecting unary plus before a floatОткрыть песочницу →
    1. let value = +1.5
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz --compiler self --format json
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    Write 1.5 to use the floating value.

    Using ordinary values, negation, and binary addition

    Ссылка
    example.tpzUsing ordinary values, negation, and binary additionОткрыть песочницу →
    1. import std.io
    2. let value = 3
    3. io.writeLine("{1}")
    4. io.writeLine("{1.5}")
    5. io.writeLine("{value}")
    6. io.writeLine("{-value}")
    7. io.writeLine("{value + 2}")
    Ожидаемый выводКод завершения 0
    1
    1.5
    3
    -3
    5
    
    $ topaz run example.tpz --compiler self
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 1
    2. 1.5
    3. 3
    4. -3
    5. 5

    Ordinary values need no identity prefix. Unary minus and binary addition retain their arithmetic meanings.

    Use in for arrays, sets, and ranges

    Ссылка
    example.tpzUse in for arrays, sets, and rangesОткрыть песочницу →
    1. import std.io
    2. let values = [1, 3]
    3. let members = set { 1, 3 }
    4. let odds = 1..<5 by 2
    5. io.writeLine("{1 in values}:{2 in values}")
    6. io.writeLine("{1 in members}:{2 in members}")
    7. io.writeLine("{1 in odds}:{2 in odds}")
    Ожидаемый выводКод завершения 0
    true:false
    true:false
    true:false
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. true:false
    2. true:false
    3. true:false

    A Map is not an element-membership container

    Ссылка
    example.tpzA Map is not an element-membership containerОткрыть песочницу →
    1. let found = "key" in map { "key": 1 }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    Контракт обязательного основного местоположения не определён.

    Substring search is not element membership

    Ссылка
    example.tpzSubstring search is not element membershipОткрыть песочницу →
    1. let found = "a" in "abc"
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    Контракт обязательного основного местоположения не определён.

    Keep combining marks, Hangul, and emoji in their grapheme clusters

    Ссылка
    example.tpzKeep combining marks, Hangul, and emoji in their grapheme clustersОткрыть песочницу →
    1. import std.io
    2. let text = "é가👩‍💻🇰🇷"
    3. let clusters = text.graphemes()
    4. io.writeLine("{text.scalars().length}:{clusters.length}")
    5. io.writeLine("{clusters[0] == "é"}")
    6. io.writeLine("{clusters[1] == "가"}")
    7. io.writeLine("{clusters[2] == "👩‍💻"}")
    8. io.writeLine("{clusters[3] == "🇰🇷"}")
    9. io.writeLine("{clusters.join("") == text}")
    Ожидаемый выводКод завершения 0
    9:4
    true
    true
    true
    true
    true
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 9:4
    2. true
    3. true
    4. true
    5. true
    6. true

    Segment empty text, CRLF, leading marks, and regional indicators

    Ссылка
    example.tpzSegment empty text, CRLF, leading marks, and regional indicatorsОткрыть песочницу →
    1. import std.io
    2. let empty = "".graphemes()
    3. let lineBreak = "\r\n".graphemes()
    4. let marks = "́̂".graphemes()
    5. let flags = "🇰🇷🇯".graphemes()
    6. io.writeLine("{empty.length}:{lineBreak.length}:{marks.length}:{flags.length}")
    7. io.writeLine("{lineBreak[0] == "\r\n"}")
    8. io.writeLine("{marks[0].scalars().length}")
    9. io.writeLine("{flags[0] == "🇰🇷"}:{flags[1] == "🇯"}")
    Ожидаемый выводКод завершения 0
    0:1:1:2
    true
    2
    true:true
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 0:1:1:2
    2. true
    3. 2
    4. true:true

    Reject a pipeline into a bare callable

    Ссылка
    example.tpzReject a pipeline into a bare callableОткрыть песочницу →
    1. function increment(n: int) -> int { n + 1 }
    2. let value = 3 |> increment
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    Контракт обязательного основного местоположения не определён.

    Reject implicit pipeline argument insertion

    Ссылка
    example.tpzReject implicit pipeline argument insertionОткрыть песочницу →
    1. function add(a: int, b: int) -> int { a + b }
    2. let value = 3 |> add(4)
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    Контракт обязательного основного местоположения не определён.

    Reject a pipeline placeholder

    Ссылка
    example.tpzReject a pipeline placeholderОткрыть песочницу →
    1. function subtract(a: int, b: int) -> int { a - b }
    2. let value = 3 |> subtract(10, _)
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    Контракт обязательного основного местоположения не определён.

    Reject a pipeline member shortcut

    Ссылка
    example.tpzReject a pipeline member shortcutОткрыть песочницу →
    1. let item = { answer: 7 }
    2. let value = item |> .answer
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    Контракт обязательного основного местоположения не определён.

    Reject the composition operator

    Ссылка
    example.tpzReject the composition operatorОткрыть песочницу →
    1. function increment(n: int) -> int { n + 1 }
    2. function double(n: int) -> int { n * 2 }
    3. let composed = increment >> double
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    Контракт обязательного основного местоположения не определён.

    Reject a standalone expression placeholder

    Ссылка
    example.tpzReject a standalone expression placeholderОткрыть песочницу →
    1. let value = _
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    Контракт обязательного основного местоположения не определён.

    Save values to preserve call and composition effects

    Ссылка
    example.tpzSave values to preserve call and composition effectsОткрыть песочницу →
    1. import std.io
    2. function input() -> int {
    3. io.writeLine("input")
    4. 3
    5. }
    6. function subtract(a: int, b: int) -> int { a - b }
    7. function stage() -> (int, int) -> int {
    8. io.writeLine("callee")
    9. subtract
    10. }
    11. function argument() -> int {
    12. io.writeLine("argument")
    13. 10
    14. }
    15. let saved = input()
    16. let callee = stage()
    17. let written = argument()
    18. io.writeLine("{callee(written, saved)}")
    19. function increment(n: int) -> int { n + 1 }
    20. function double(n: int) -> int { n * 2 }
    21. function first() -> (int) -> int {
    22. io.writeLine("first")
    23. increment
    24. }
    25. function second() -> (int) -> int {
    26. io.writeLine("second")
    27. double
    28. }
    29. let left = first()
    30. let right = second()
    31. let composed = (n: int) => right(left(n))
    32. io.writeLine("{composed(3)}:{composed(5)}")
    Ожидаемый выводКод завершения 0
    input
    callee
    argument
    7
    first
    second
    8:12
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. input
    2. callee
    3. argument
    4. 7
    5. first
    6. second
    7. 8:12

    Reject an undelimited if operand

    Ссылка
    example.tpzReject an undelimited if operandОткрыть песочницу →
    1. let value = if true { 1 } else { 0 }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:1:16

    Reject an undelimited if let operand

    Ссылка
    example.tpzReject an undelimited if let operandОткрыть песочницу →
    1. let value = if let Some(item) = Some(1) { item } else { 0 }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:1:33

    Reject an undelimited while operand

    Ссылка
    example.tpzReject an undelimited while operandОткрыть песочницу →
    1. while false { () }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:1:7

    Reject an undelimited while let operand

    Ссылка
    example.tpzReject an undelimited while let operandОткрыть песочницу →
    1. let mut value: Option<int> = None()
    2. while let Some(item) = value { value = None() }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:2:24

    Reject an undelimited for operand

    Ссылка
    example.tpzReject an undelimited for operandОткрыть песочницу →
    1. for item in [1] { let _ = item }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:1:13

    Reject an undelimited using operand

    Ссылка
    example.tpzReject an undelimited using operandОткрыть песочницу →
    1. function manage(file: File) -> () {
    2. using resource = file {}
    3. }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:2:20

    Reject an undelimited match operand

    Ссылка
    example.tpzReject an undelimited match operandОткрыть песочницу →
    1. let value = match 1 { case _ => 2 }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:1:19

    Reject an undelimited match guard operand

    Ссылка
    example.tpzReject an undelimited match guard operandОткрыть песочницу →
    1. let value = match (1) {
    2. case 1 if true => 1
    3. case _ => 0
    4. }
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:2:13

    Reject an undelimited comprehension iterable operand

    Ссылка
    example.tpzReject an undelimited comprehension iterable operandОткрыть песочницу →
    1. let values = [for item in [1] => item]
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:1:27

    Reject an undelimited comprehension filter operand

    Ссылка
    example.tpzReject an undelimited comprehension filter operandОткрыть песочницу →
    1. let values = [for item in ([1]) if true => item]
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения parse. Ненулевой код завершения.

    • TPZ2001 →

      control-operand-parentheses at example.tpz:1:36

    Delimited tests, iterators, scrutinees, and guards

    Ссылка
    example.tpzDelimited tests, iterators, scrutinees, and guardsОткрыть песочницу →
    1. import std.io
    2. let mut count = 0
    3. if (true) { count += 1 }
    4. if let Some(value) = (Some(1)) { count += value }
    5. while (count < 3) { count += 1 }
    6. let mut pending: Option<int> = Some(1)
    7. while let Some(value) = (pending) { pending = None() }
    8. for value in ([1, 2]) { count += value }
    9. let chosen = match (count) {
    10. case 6 if (((flag: bool) => flag)(true)) => 6
    11. case _ => 0
    12. }
    13. let collected = [for value in ([1, 2]) if (((flag: bool) => flag)(value > 0)) => value]
    14. io.writeLine("{chosen}")
    15. io.writeLine("{collected.length}")
    Ожидаемый выводКод завершения 0
    6
    2
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 6
    2. 2

    Record construction and update use ordinary operand grammar

    Ссылка
    example.tpzRecord construction and update use ordinary operand grammarОткрыть песочницу →
    1. import std.io
    2. record Flag { enabled: bool }
    3. let state = { enabled: true }
    4. let first = if (Flag { enabled: true }.enabled) { 1 } else { 0 }
    5. let second = if (state { enabled: false }.enabled) { 1 } else { 2 }
    6. let third = match (Flag { enabled: true }) {
    7. case Flag { enabled: true } => true
    8. case _ => false
    9. }
    10. io.writeLine("{first},{second},{third}")
    Ожидаемый выводКод завершения 0
    1,2,true
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 1,2,true

    The using expression has the same required boundary

    Ссылка
    example.tpzThe using expression has the same required boundaryОткрыть песочницу →
    1. function manage(file: File) -> () {
    2. using resource = (file) {
    3. let handle: File = resource
    4. }
    5. }
    Ожидаемый выводКод завершения 0
    Нет стандартного вывода.
    $ topaz check example.tpz --compiler self --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Проверка принимает программу. Код завершения 0.

    Read transformations in data-flow order

    Ссылка
    example.tpzRead transformations in data-flow orderОткрыть песочницу →
    1. import std.io
    2. function increment(value: int) -> int { value + 1 }
    3. function double(value: int) -> int { value * 2 }
    4. function transform(value: int) -> int {
    5. let increased = increment(value)
    6. double(increased)
    7. }
    8. let values = [1, 2]
    9. let chained = values.map(increment).map(double)
    10. let increased = values.map(increment)
    11. let staged = increased.map(double)
    12. let composed = values.map(transform)
    13. io.writeLine("{chained[0]},{chained[1]}")
    14. io.writeLine("{staged[0]},{staged[1]}")
    15. io.writeLine("{composed[0]},{composed[1]}")
    Ожидаемый выводКод завершения 0
    4,6
    4,6
    4,6
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 4,6
    2. 4,6
    3. 4,6

    Binary and nested operands print from left to right

    Ссылка
    example.tpzBinary and nested operands print from left to rightОткрыть песочницу →
    1. import std.io
    2. function value(label: string, number: int) -> int {
    3. io.writeLine(label)
    4. number
    5. }
    6. let result = value("left", 1) + value("middle", 2) * value("right", 3)
    7. io.writeLine("{result}")
    Ожидаемый выводКод завершения 0
    left
    middle
    right
    7
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. left
    2. middle
    3. right
    4. 7

    The left operand faults before the right operand runs

    Ссылка
    example.tpzThe left operand faults before the right operand runsОткрыть песочницу →
    1. import std.io
    2. function left(divisor: int) -> int {
    3. io.writeLine("left")
    4. 1 / divisor
    5. }
    6. function right(number: int) -> int {
    7. io.writeLine("right")
    8. 9223372036854775807 + number
    9. }
    10. left(0) + right(1)
    Ожидаемый выводНенулевой код завершения
    left
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения run. Ненулевой код завершения.

    Ожидаемый стандартный вывод
    1. left

    Both calls would fault if evaluated. The left call produces TPZ4002, and the right call produces no output.

    Index assignment evaluates the index before its value

    Ссылка
    example.tpzIndex assignment evaluates the index before its valueОткрыть песочницу →
    1. import std.io
    2. function index() -> int {
    3. io.writeLine("index")
    4. 0
    5. }
    6. function value() -> int {
    7. io.writeLine("value")
    8. 7
    9. }
    10. let mut values = [1]
    11. values[index()] = value()
    12. io.writeLine("{values[0]}")
    13. let mut number = 1
    14. number += value()
    15. io.writeLine("{number}")
    Ожидаемый выводКод завершения 0
    index
    value
    7
    value
    8
    
    $ topaz run example.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. index
    2. value
    3. 7
    4. value
    5. 8

    Pending contracts and verification

    Ссылка

    Related contracts and diagnostic

    Ссылка

    Functions and generics →

    Unexpected token →

    TPZ5001 →

    Unknown member or field →

    Division or remainder by zero →

    Меню

    Загрузка →