mbeckerle commented on code in PR #1293:
URL: https://github.com/apache/daffodil/pull/1293#discussion_r1747735949
##########
daffodil-core/src/main/scala/org/apache/daffodil/core/grammar/ElementBaseGrammarMixin.scala:
##########
@@ -1611,37 +1611,47 @@ trait ElementBaseGrammarMixin
)
case _ => // ok
}
+
/*
- * When lengthKind is explicit and length is a constant, it is a warning if
- * the type is a type that respects minLength and maxLength, and the
constant length
- * is not in range.
+ * Warn if a type respects minLength/maxLength/length facets and we can
calculate that the
+ * infoset length will be out of range of the facet values. Note that we
can only do this in
+ * specific cases, like when the length and encodig properties are
constant and the encoding
+ * is fixed width characters.
*/
- val isTypeUsingLengthOrMinMaxLengthFacets = typeDef.typeNode match {
- case s: NodeInfo.String.Kind => true
- case s: NodeInfo.HexBinary.Kind => true
- case _ => false
- }
- if (
- (lengthKind eq LengthKind.Explicit) &&
- isTypeUsingLengthOrMinMaxLengthFacets &&
- optLengthConstant.isDefined
- ) {
- val len = optLengthConstant.get
- lazy val maxLengthLong = maxLength.longValueExact
- lazy val minLengthLong = minLength.longValueExact
- def warn(m: String, value: Long): Unit = SDW(
- WarnID.FacetExplicitLengthOutOfRange,
- "Explicit dfdl:length of %s is out of range for facet %s='%s'.",
- len,
- m,
- value
- )
- if (hasLength && len != minLengthLong && len != maxLengthLong)
- warn("length", minLengthLong)
- else if (hasMinLength || hasMaxLength) {
- if (maxLengthLong != -1 && len > maxLengthLong) warn("maxLength",
maxLengthLong)
- Assert.invariant(minLengthLong >= 0)
- if (minLengthLong > 0 && len < minLengthLong) warn("minLength",
minLengthLong)
+ if ((lengthKind eq LengthKind.Explicit) && (hasLength || hasMinLength ||
hasMaxLength)) {
+ val optInfosetLen = elementLengthInBitsEv.optConstant.flatMap {
maybeKnownLenInBits =>
Review Comment:
naming convention. Normally the prefix "maybe" is used for things of type
Maybe. Is the type of optConstant's result a Maybe? If so then all good. I just
want to make sure we're following those conventions if all these types are
getting omitted.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]