mirror of
https://github.com/irmen/prog8.git
synced 2025-03-04 05:33:07 +00:00
allow comparisons against constant values with different type
This commit is contained in:
parent
a36bdc54fd
commit
d06e9ea7f6
10
.idea/libraries/eclipse_lsp4j.xml
generated
10
.idea/libraries/eclipse_lsp4j.xml
generated
@ -1,11 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="eclipse.lsp4j" type="repository">
|
||||
<properties maven-id="org.eclipse.lsp4j:org.eclipse.lsp4j:0.23.1" />
|
||||
<properties maven-id="org.eclipse.lsp4j:org.eclipse.lsp4j:0.24.0" />
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/lsp4j/org.eclipse.lsp4j/0.23.1/org.eclipse.lsp4j-0.23.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/lsp4j/org.eclipse.lsp4j.jsonrpc/0.23.1/org.eclipse.lsp4j.jsonrpc-0.23.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.11.0/gson-2.11.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.27.0/error_prone_annotations-2.27.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/lsp4j/org.eclipse.lsp4j/0.24.0/org.eclipse.lsp4j-0.24.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/lsp4j/org.eclipse.lsp4j.jsonrpc/0.24.0/org.eclipse.lsp4j.jsonrpc-0.24.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.12.1/gson-2.12.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.36.0/error_prone_annotations-2.36.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
|
@ -1276,17 +1276,6 @@ internal class AstChecker(private val program: Program,
|
||||
// str+str and str*number have already been const evaluated before we get here.
|
||||
errors.err("no computational or logical expressions with strings or arrays are possible", expr.position)
|
||||
}
|
||||
} else {
|
||||
if(expr.left is TypecastExpression && expr.right is NumericLiteral && !(expr.right.inferType(program) issimpletype BaseDataType.FLOAT)) {
|
||||
val origLeftDt = (expr.left as TypecastExpression).expression.inferType(program).getOrUndef()
|
||||
if(rightDt.largerSizeThan(origLeftDt) && !(expr.right as NumericLiteral).cast(origLeftDt.base, true).isValid)
|
||||
errors.err("operands are not the same type", expr.right.position)
|
||||
}
|
||||
if(expr.right is TypecastExpression && expr.left is NumericLiteral && !(expr.left.inferType(program) issimpletype BaseDataType.FLOAT)) {
|
||||
val origRightDt = (expr.right as TypecastExpression).expression.inferType(program).getOrUndef()
|
||||
if(leftDt.largerSizeThan(origRightDt) && !(expr.left as NumericLiteral).cast(origRightDt.base, true).isValid)
|
||||
errors.err("operands are not the same type", expr.right.position)
|
||||
}
|
||||
}
|
||||
|
||||
if(leftDt.isBool || rightDt.isBool ||
|
||||
|
@ -954,4 +954,17 @@ main {
|
||||
(v4.right as NumericLiteral).type shouldBe BaseDataType.UWORD
|
||||
(v4.right as NumericLiteral).number shouldBe 5
|
||||
}
|
||||
|
||||
test("allow comparisons against constant values with different type") {
|
||||
val src = """
|
||||
main {
|
||||
sub start() {
|
||||
const uword MAX_CAVE_WIDTH = 440 ; word here to avoid having to cast to word all the time
|
||||
|
||||
if cx16.r0L > MAX_CAVE_WIDTH
|
||||
return
|
||||
}
|
||||
}"""
|
||||
compileText(C64Target(), false, src, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
@ -3,23 +3,10 @@
|
||||
|
||||
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
const uword x=128
|
||||
const uword MAX_CAVE_WIDTH = 440 ; word here to avoid having to cast to word all the time
|
||||
|
||||
const uword MAX_CAVE_WIDTH = 40 ; word here to avoid having to cast to word all the time
|
||||
ubyte @shared width
|
||||
|
||||
if cx16.r0L==x
|
||||
if cx16.r0L > MAX_CAVE_WIDTH
|
||||
return
|
||||
if cx16.r0L>x
|
||||
return
|
||||
if cx16.r0L<x
|
||||
return
|
||||
|
||||
if width<3 or width>MAX_CAVE_WIDTH ; TODO optimize this too
|
||||
return
|
||||
|
||||
cx16.r0L = x ; already gets optimized to a byte value
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,4 @@ org.gradle.console=rich
|
||||
org.gradle.parallel=true
|
||||
org.gradle.daemon=true
|
||||
kotlin.code.style=official
|
||||
version=11.1
|
||||
version=11.2-SNAPSHOT
|
||||
|
Loading…
x
Reference in New Issue
Block a user