private final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target;
private final AbstractAugmentStatementSupport statementSupport;
+ private boolean targetUnavailable;
+
AugmentInferenceAction(final AbstractAugmentStatementSupport statementSupport,
final Mutable<SchemaNodeIdentifier, AugmentStatement, AugmentEffectiveStatement> augmentNode,
final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target) {
@Override
public void apply(final InferenceContext ctx) {
- if (!augmentNode.isSupportedToBuildEffective()) {
- // We are not building effective model, hence we should not be performing any effects
+ if (targetUnavailable) {
+ // Target node is not available, no further processing and the augment should not leak into effective world
+ augmentNode.setUnsupported();
return;
}
@Override
public void prerequisiteUnavailable(final Prerequisite<?> unavail) {
if (target.equals(unavail)) {
- augmentNode.setUnsupported();
+ targetUnavailable = true;
} else {
prerequisiteFailed(List.of(unavail));
}
--- /dev/null
+/*
+ * Copyright (c) 2023 Verizon and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.stmt;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.not;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import java.util.Set;
+import org.junit.jupiter.api.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
+
+class YT1485Test extends AbstractYangTest {
+ private static final QName FOO = QName.create("urn:foo", "foo");
+
+ @Test
+ void testLeafFooFeatureSupported() {
+ assertEquals(List.of(), assertFoo("leaf", null).effectiveSubstatements());
+ }
+
+ @Test
+ void testLeafFooFeatureNotSupported() {
+ assertEquals(List.of(), assertFoo("leaf", Set.of()).effectiveSubstatements());
+ }
+
+ @Test
+ void testAugmentFooFeatureSupported() {
+ assertThat(assertFoo("augment", null).effectiveSubstatements(),
+ not(hasItem(instanceOf(LeafEffectiveStatement.class))));
+ }
+
+ @Test
+ void testAugmentFooFeatureNotSupported() {
+ assertEquals(List.of(), assertFoo("augment", Set.of()).effectiveSubstatements());
+ }
+
+ private static ContainerEffectiveStatement assertFoo(final String dirName,
+ final Set<QName> supportedFeatures) {
+ final var foo = assertEffectiveModelDir("/bugs/YT1485/" + dirName, supportedFeatures)
+ .findModuleStatement(FOO).orElseThrow()
+ .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
+ assertEquals(FOO, foo.argument());
+ return foo;
+ }
+}