mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Address warning diagnostics (#1395)
This addressess various warning diagnostics throughout the codebase.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -105,7 +105,8 @@ final class JsonRenderer implements ValueRenderer {
|
||||
@Override
|
||||
public void visitBytes(byte[] value) {
|
||||
throw new RendererException(
|
||||
String.format("Values of type `Bytes` cannot be rendered as JSON. Value: %s", value));
|
||||
String.format(
|
||||
"Values of type `Bytes` cannot be rendered as JSON. Value: %s", (Object) value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -110,7 +110,8 @@ final class PropertiesRenderer implements ValueRenderer {
|
||||
public String convertBytes(byte[] value) {
|
||||
throw new RendererException(
|
||||
String.format(
|
||||
"Values of type `Bytes` cannot be rendered as Properties. Value: %s", value));
|
||||
"Values of type `Bytes` cannot be rendered as Properties. Value: %s",
|
||||
(Object) value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -2449,8 +2449,7 @@ public class AstBuilder extends AbstractAstBuilder<Object> {
|
||||
if (dataSizeUnit != null) {
|
||||
//noinspection ConstantConditions
|
||||
return new ConstantValueNode(
|
||||
sourceSection,
|
||||
new VmDataSize(((IntLiteralNode) receiver).executeInt(null), dataSizeUnit));
|
||||
sourceSection, new VmDataSize(intLiteralNode.executeInt(null), dataSizeUnit));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2465,8 +2464,7 @@ public class AstBuilder extends AbstractAstBuilder<Object> {
|
||||
if (dataSizeUnit != null) {
|
||||
//noinspection ConstantConditions
|
||||
return new ConstantValueNode(
|
||||
sourceSection,
|
||||
new VmDataSize(((FloatLiteralNode) receiver).executeFloat(null), dataSizeUnit));
|
||||
sourceSection, new VmDataSize(floatLiteralNode.executeFloat(null), dataSizeUnit));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -100,6 +100,7 @@ public abstract class NotEqualNode extends ExpressionNode {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("JavaExistingMethodCanBeUsed")
|
||||
protected static boolean isIncompatibleTypes(Object left, Object right) {
|
||||
var leftClass = left.getClass();
|
||||
var rightClass = right.getClass();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -67,7 +67,6 @@ public abstract class SpecializedObjectLiteralNode extends ObjectLiteralNode {
|
||||
|
||||
// only runs once per VmClass (which often means once per PropertiesLiteralNode)
|
||||
// unless an XYZUncached specialization is active
|
||||
@SuppressWarnings("ExtractMethodRecommender")
|
||||
@TruffleBoundary
|
||||
@Idempotent
|
||||
protected boolean checkIsValidTypedAmendment(Object parent) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,7 +62,6 @@ import org.pkl.core.util.ErrorMessages;
|
||||
import org.pkl.core.util.GlobResolver;
|
||||
import org.pkl.core.util.GlobResolver.InvalidGlobPatternException;
|
||||
import org.pkl.core.util.IoUtils;
|
||||
import org.pkl.core.util.Nullable;
|
||||
|
||||
/**
|
||||
* Given a list of project directories, prepares artifacts to be published as a package.
|
||||
@@ -441,7 +440,7 @@ public final class ProjectPackager {
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable List<ImportsAndReadsParser.Entry> getImportsAndReads(Path pklModulePath) {
|
||||
private List<ImportsAndReadsParser.Entry> getImportsAndReads(Path pklModulePath) {
|
||||
try {
|
||||
var moduleKey = ModuleKeys.file(pklModulePath);
|
||||
var resolvedModuleKey = ResolvedModuleKeys.file(moduleKey, moduleKey.getUri(), pklModulePath);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,7 +63,11 @@ final class MinPklVersionChecker {
|
||||
if (!Identifier.MIN_PKL_VERSION.toString().equals(prop.getIdentifier().getValue()))
|
||||
continue;
|
||||
|
||||
var versionText = prop.getExpr().text(source.toCharArray());
|
||||
var versionTextExpr = prop.getExpr();
|
||||
if (versionTextExpr == null) {
|
||||
return;
|
||||
}
|
||||
var versionText = versionTextExpr.text(source.toCharArray());
|
||||
|
||||
Version version;
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2025-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,7 @@ public final class VmBytes extends VmValue implements Iterable<Long> {
|
||||
private final byte[] bytes;
|
||||
private @Nullable VmDataSize size;
|
||||
|
||||
public static VmBytes EMPTY = new VmBytes(new byte[0]);
|
||||
public static final VmBytes EMPTY = new VmBytes(new byte[0]);
|
||||
|
||||
@TruffleBoundary
|
||||
public static VmBytes createFromConstantNodes(ExpressionNode[] elements) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -100,7 +100,8 @@ public final class VmDynamic extends VmObject {
|
||||
@Override
|
||||
@TruffleBoundary
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (this == obj) // noinspection Contract
|
||||
return true;
|
||||
if (!(obj instanceof VmDynamic other)) return false;
|
||||
|
||||
// could use shallow force, but deep force is cached
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -94,9 +94,6 @@ public class VmImportAnalyzer {
|
||||
} catch (IOException err) {
|
||||
throw new VmExceptionBuilder().evalError("ioErrorLoadingModule", moduleKey.getUri()).build();
|
||||
}
|
||||
if (importsAndReads == null) {
|
||||
return Set.of();
|
||||
}
|
||||
var result = new HashSet<ImportEntry>();
|
||||
for (var entry : importsAndReads) {
|
||||
if (!entry.isModule()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -119,7 +119,8 @@ public final class VmMapping extends VmListingOrMapping {
|
||||
@Override
|
||||
@TruffleBoundary
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (this == obj) // noinspection Contract
|
||||
return true;
|
||||
if (!(obj instanceof VmMapping other)) return false;
|
||||
|
||||
// could use shallow force, but deep force is cached
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -52,14 +52,14 @@ public final class BaseNodes {
|
||||
|
||||
public abstract static class NaN extends ExternalPropertyNode {
|
||||
@Specialization
|
||||
protected double eval(VmTyped self) {
|
||||
protected double eval(VmTyped ignored) {
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class Infinity extends ExternalPropertyNode {
|
||||
@Specialization
|
||||
protected double eval(VmTyped self) {
|
||||
protected double eval(VmTyped ignored) {
|
||||
return Double.POSITIVE_INFINITY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,8 @@ public final class DataSizeNodes {
|
||||
private DataSizeNodes() {}
|
||||
|
||||
@ImportStatic(MathUtils.class)
|
||||
public abstract static class value extends ExternalPropertyNode {
|
||||
@PklName("value")
|
||||
public abstract static class valueProperty extends ExternalPropertyNode {
|
||||
@Specialization(guards = "isMathematicalInteger(self.getValue())")
|
||||
protected long evalInt(VmDataSize self) {
|
||||
return (long) self.getValue();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,8 @@ public final class DurationNodes {
|
||||
private DurationNodes() {}
|
||||
|
||||
@ImportStatic(MathUtils.class)
|
||||
public abstract static class value extends ExternalPropertyNode {
|
||||
@PklName("value")
|
||||
public abstract static class valueProperty extends ExternalPropertyNode {
|
||||
@Specialization(guards = "isMathematicalInteger(self.getValue())")
|
||||
protected long evalInt(VmDuration self) {
|
||||
return (long) self.getValue();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package org.pkl.core.stdlib.base;
|
||||
import com.oracle.truffle.api.dsl.Specialization;
|
||||
import org.pkl.core.runtime.VmPair;
|
||||
import org.pkl.core.stdlib.ExternalPropertyNode;
|
||||
import org.pkl.core.stdlib.PklName;
|
||||
|
||||
public final class PairNodes {
|
||||
private PairNodes() {}
|
||||
@@ -43,7 +44,8 @@ public final class PairNodes {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class value extends ExternalPropertyNode {
|
||||
@PklName("value")
|
||||
public abstract static class valueProperty extends ExternalPropertyNode {
|
||||
@Specialization
|
||||
protected Object eval(VmPair self) {
|
||||
return self.getSecond();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,6 @@ import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import org.graalvm.collections.EconomicMap;
|
||||
import org.pkl.core.TestResults;
|
||||
import org.pkl.core.TestResults.Error;
|
||||
@@ -57,9 +56,8 @@ public final class JUnitReport implements TestReport {
|
||||
|
||||
@Override
|
||||
public void summarize(List<TestResults> allTestResults, Writer writer) throws IOException {
|
||||
var totalTests = allTestResults.stream().collect(Collectors.summingLong(r -> r.totalTests()));
|
||||
var totalFailures =
|
||||
allTestResults.stream().collect(Collectors.summingLong(r -> r.totalFailures()));
|
||||
var totalTests = allTestResults.stream().mapToLong(TestResults::totalTests).sum();
|
||||
var totalFailures = allTestResults.stream().mapToLong(TestResults::totalFailures).sum();
|
||||
|
||||
assert aggregateSuiteName != null;
|
||||
|
||||
@@ -69,12 +67,11 @@ public final class JUnitReport implements TestReport {
|
||||
"tests", totalTests,
|
||||
"failures", totalFailures);
|
||||
|
||||
var tests =
|
||||
allTestResults.stream()
|
||||
.map(r -> buildSuite(r))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
var suite = buildXmlElement("testsuites", attrs, tests.toArray(new VmDynamic[0]));
|
||||
var suite =
|
||||
buildXmlElement(
|
||||
"testsuites",
|
||||
attrs,
|
||||
allTestResults.stream().map(this::buildSuite).toArray(VmDynamic[]::new));
|
||||
|
||||
writer.append(renderXML(" ", "1.0", suite));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -362,7 +362,7 @@ public final class Json {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object put(String key, Object value) {
|
||||
public @Nullable Object put(String key, Object value) {
|
||||
return delegate.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2025-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,14 +17,11 @@ package org.pkl.core.parser
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.pkl.core.Evaluator
|
||||
import org.pkl.parser.Parser
|
||||
|
||||
// tests type argument and parameter parsing with trailing commas that cannot be tested with
|
||||
// snippets because these constructs are currently only allowed in the stdlib
|
||||
class TrailingCommasTest {
|
||||
private val evaluator = Evaluator.preconfigured()
|
||||
|
||||
@Test
|
||||
fun `class type parameter lists parse correctly`() {
|
||||
val module =
|
||||
|
||||
Reference in New Issue
Block a user