diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-02-20 18:54:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-20 18:54:29 +0100 |
commit | f467be62da8978e506f58b702b84e74ef7ce09de (patch) | |
tree | 1ac2e53a51bb60b8ab7bd7e554fa071f0252f7df /compiler/src/dotty/tools/dotc/reporting | |
parent | f76ffe97f9460cc04e159ce5b2c0b83d63fb940c (diff) | |
parent | 6b522cc16ee61b51c5b0c5ff4df3632c2d84e801 (diff) | |
download | dotty-f467be62da8978e506f58b702b84e74ef7ce09de.tar.gz dotty-f467be62da8978e506f58b702b84e74ef7ce09de.tar.bz2 dotty-f467be62da8978e506f58b702b84e74ef7ce09de.zip |
Merge pull request #2007 from dotty-staging/ennru_MixedLeftAndRightAssoc
mixed left and right assoc
Diffstat (limited to 'compiler/src/dotty/tools/dotc/reporting')
-rw-r--r-- | compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java | 3 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 34 |
2 files changed, 36 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index 43930a56e..c74130b44 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -48,7 +48,8 @@ public enum ErrorMessageID { OverridesNothingID, OverridesNothingButNameExistsID, ForwardReferenceExtendsOverDefinitionID, - ExpectedTokenButFoundID; + ExpectedTokenButFoundID, + MixedLeftAndRightAssociativeOpsID; public int errorNumber() { return ordinal() - 2; diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 3ca780419..7fccebef9 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1093,4 +1093,38 @@ object messages { |""".stripMargin } + case class MixedLeftAndRightAssociativeOps(op1: Name, op2: Name, op2LeftAssoc: Boolean)(implicit ctx: Context) + extends Message(MixedLeftAndRightAssociativeOpsID) { + val kind = "Syntax" + val op1Asso = if (op2LeftAssoc) "which is right-associative" else "which is left-associative" + val op2Asso = if (op2LeftAssoc) "which is left-associative" else "which is right-associative" + val msg = s"`${op1}` (${op1Asso}) and `${op2}` ($op2Asso) have same precedence and may not be mixed" + val explanation = + s"""|The operators ${op1} and ${op2} are used as infix operators in the same expression, + |but they bind to different sides: + |${op1} is applied to the operand to its ${if (op2LeftAssoc) "right" else "left"} + |${op2} is applied to the operand to its ${if (op2LeftAssoc) "left" else "right"} + |As both have the same precedence the compiler can't decide which to apply first. + | + |You may use parenthesis to make the application order explicit, + |or use method application syntax `operand1.${op1}(operand2)`. + | + |Operators ending in a colon `:` are right-associative. All other operators are left-associative. + | + |Infix operator precedence is determined by the operator's first character. Characters are listed + |below in increasing order of precedence, with characters on the same line having the same precedence. + | (all letters) + | | + | ^ + | & + | = ! + | < > + | : + | + - + | * / % + | (all other special characters) + |Operators starting with a letter have lowest precedence, followed by operators starting with `|`, etc. + |""".stripMargin + } + } |