Skip to content

Commit

Permalink
flow fix, unit tests, reword error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruzihm committed Feb 23, 2025
1 parent 54de75b commit 0582e24
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 11 deletions.
17 changes: 12 additions & 5 deletions Content.Tests/DMProject/Tests/Operators/scope.dm
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/datum
var/static/datum/three/three
var/text = "hello"

var/static/one = "one"

/datum/three
var/static/datum/four/four
text = "hi"
var/overridden_text = type::text
var/original_text = parent_type::text

/datum/three/proc/typetest()
// initial shorthand, type:: and parent_type::
ASSERT(text == "hi")
Expand All @@ -21,7 +21,7 @@ var/static/one = "one"
ASSERT(src::text == "hi")
ASSERT(src::overridden_text == "hi")
ASSERT(src::original_text == "hello")

// proc reference
ASSERT(__PROC__ == /datum/three::typetest())

Expand All @@ -34,6 +34,11 @@ var/static/one = "one"
/proc/return_two()
return "two"

/datum/six
var/price = 60
better
price = parent_type::price + 40

/proc/RunTest()
// global vars and procs
ASSERT(::one == "one")
Expand All @@ -52,10 +57,12 @@ var/static/one = "one"
ASSERT(test::three::four.five::six == "3 4 5 6")
ASSERT(/datum::three::four.five::six == "3 4 5 6")

// this does not compile in BYOND, that is just a bug
// this does not compile in BYOND, that is just a bug
test::three::four.five::six = "7 8 9 10"
ASSERT(test::three::four.five::six == "7 8 9 10")
ASSERT(/datum::three::four.five::six == "7 8 9 10")

var/datum/three/threetest = new
threetest.typetest()

var/datum/six/better/test
10 changes: 10 additions & 0 deletions Content.Tests/DMProject/Tests/Operators/scope_parent_type_fails.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// COMPILE ERROR OD0011

/datum/thing
var/price = 60
better
proc/test_proc()
price = parent_type::price + 40

/proc/RunTest()
var/datum/thing/better/test
8 changes: 4 additions & 4 deletions DMCompiler/DM/Builders/DMExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,16 +644,16 @@ private DMExpression BuildScopeIdentifier(DMASTScopeIdentifier scopeIdentifier,
if (scopeIdentifier.Expression is DMASTIdentifier { Identifier: "type" or "parent_type" } identifier) {
// This is the same behaviour as in BYOND, but BYOND simply raises an undefined var error.
// We want to give end users an explanation at least.
if (scopeMode is Normal && ctx.Proc != null)
if (scopeMode is Normal && ctx.Proc != null) {
if (ctx.Proc.GetLocalVariable(identifier.Identifier) != null) {
// actually - it's referring to a local variable named "type" or "parent_type"... just do the usual thing
expression = BuildExpression(scopeIdentifier.Expression, inferredPath);
} else {
return BadExpression(WarningCode.BadExpression, identifier.Location,
"Use of \"type::\" and \"parent_type::\" outside of a context is forbidden");
"Use of \"type::\" and \"parent_type::\" inside an object proc is only valid when " +
"there is a local variable named \"type\" or \"parent_type\"");
}

if (identifier.Identifier == "parent_type") {
} else if (identifier.Identifier == "parent_type") {
if (ctx.Type.Parent == null)
return BadExpression(WarningCode.ItemDoesntExist, identifier.Location,
$"Type {ctx.Type.Path} does not have a parent");
Expand Down
Loading

0 comments on commit 0582e24

Please sign in to comment.