Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use plc_ast::{
use plc_source::source_location::SourceLocation;
use plc_util::convention::internal_type_name;

use crate::index::{FxIndexMap, FxIndexSet, InterfaceIndexEntry};
use crate::typesystem::VOID_INTERNAL_NAME;
use crate::{
builtins::{self, BuiltIn},
Expand All @@ -35,6 +34,10 @@ use crate::{
REAL_TYPE, TIME_OF_DAY_TYPE, TIME_TYPE, VOID_TYPE, WORD_TYPE,
},
};
use crate::{
index::{FxIndexMap, FxIndexSet, InterfaceIndexEntry},
typesystem::UDINT_TYPE,
};

pub mod const_evaluator;
pub mod generics;
Expand Down Expand Up @@ -427,10 +430,16 @@ impl TypeAnnotator<'_> {
get_bigger_type(data_type, self.index.get_type_or_panic(LREAL_TYPE), self.index)
.get_name()
}
DataTypeInformation::Integer { .. }
DataTypeInformation::Integer { signed, .. }
if !data_type.information.is_bool() && !data_type.information.is_character() =>
{
get_bigger_type(data_type, self.index.get_type_or_panic(DINT_TYPE), self.index).get_name()
let right_type = if *signed {
self.index.get_type_or_panic(DINT_TYPE)
} else {
self.index.get_type_or_panic(UDINT_TYPE)
};

get_bigger_type(data_type, right_type, self.index).get_name()
}
// Enum types need to be promoted based on their underlying integer type
DataTypeInformation::Enum { referenced_type, .. } => self
Expand Down
4 changes: 2 additions & 2 deletions src/resolver/tests/resolve_expressions_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
test_utils::tests::{annotate_with_ids, index_with_ids},
typesystem::{
DataTypeInformation, Dimension, TypeSize, BOOL_TYPE, BYTE_TYPE, DINT_TYPE, DWORD_TYPE, INT_TYPE,
LINT_TYPE, LREAL_TYPE, REAL_TYPE, SINT_TYPE, UINT_TYPE, USINT_TYPE, VOID_TYPE, WORD_TYPE,
LINT_TYPE, LREAL_TYPE, REAL_TYPE, SINT_TYPE, UDINT_TYPE, UINT_TYPE, USINT_TYPE, VOID_TYPE, WORD_TYPE,
},
};

Expand Down Expand Up @@ -3847,7 +3847,7 @@ fn undeclared_varargs_type_hint_promoted_correctly() {
assert_type_and_hint!(&annotations, &index, parameters[0], REAL_TYPE, Some(LREAL_TYPE));
assert_type_and_hint!(&annotations, &index, parameters[1], LREAL_TYPE, Some(LREAL_TYPE));
assert_type_and_hint!(&annotations, &index, parameters[2], BOOL_TYPE, None);
assert_type_and_hint!(&annotations, &index, parameters[3], USINT_TYPE, Some(DINT_TYPE));
assert_type_and_hint!(&annotations, &index, parameters[3], USINT_TYPE, Some(UDINT_TYPE));
assert_type_and_hint!(&annotations, &index, parameters[4], INT_TYPE, Some(DINT_TYPE));
assert_type_and_hint!(&annotations, &index, parameters[5], DINT_TYPE, Some(DINT_TYPE));
assert_type_and_hint!(&annotations, &index, parameters[6], LINT_TYPE, Some(LINT_TYPE));
Expand Down
33 changes: 33 additions & 0 deletions src/validation/tests/statement_validation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2712,3 +2712,36 @@ fn division_by_zero_variable_must_not_result_in_error() {

assert_snapshot!(diagnostics, @"");
}

#[test]
fn function_call_with_variadics_should_not_produce_downcast_warnings() {
let diagnostics = parse_and_validate_buffered(
"
TYPE LogLevel :
(
LOG_LEVEL_INFO := 0,
);
END_TYPE

FUNCTION Log_Print : ErrorCode
VAR_INPUT
Priority : LogLevel;
Format : STRING[1023];
Args : ...;
END_VAR
// Do nothing
END_FUNCTION

FUNCTION main
VAR
x : UDINT := 21;
y : LREAL := 42;
END_VAR

Log_Print(LOG_LEVEL_INFO, 'X(%u): Y = %f', x, y);
END_FUNCTION
",
);

assert_snapshot!(diagnostics, @"");
}
10 changes: 10 additions & 0 deletions tests/lit/single/variadics/implicit_types_passed_correctly.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: (%COMPILE %s && %RUN) | %CHECK %s
FUNCTION main: DINT
VAR
x : UDINT := 21;
y : LREAL := 42;
END_VAR

// CHECK: X(21): Y = 42.000000
printf('X(%u): Y = %f', x, y);
END_FUNCTION
Loading