Skip to content

Commit

Permalink
Fix more flow types
Browse files Browse the repository at this point in the history
  • Loading branch information
jlchmura committed Jan 9, 2025
1 parent 60f6852 commit f96c8a3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
// "${workspaceRoot}/../StickLib",
// "${workspaceRoot}/../mg-mudlib",
// "${workspaceRoot}/../lima",
"${workspaceRoot}/../lpc-test2",
// "${workspaceRoot}/../lpc-test2",
// "${workspaceRoot}/../glpu-john",
// "${workspaceRoot}/../nightmare-residuum",
"${workspaceRoot}/../nightmare-residuum",
// "${workspaceRoot}/../infinity-lib",
// "${workspaceRoot}/../fluff-test",
//"${workspaceRoot}/efuns/ldmud",
Expand Down
5 changes: 2 additions & 3 deletions efuns/fluffos/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ mixed *shuffle(mixed *arr);

/**
* pointerp() - identifies whether a given variable is an array
* @template {ALL_PRIMITIVE_TYPES} T
* @param {T|T*} arg The argument to check
* @returns {arg is T*} 1 if 'arg' is an array, otherwise returns 0.
* @param {mixed} arg The argument to check
* @returns {arg is mixed*} 1 if 'arg' is an array, otherwise returns 0.
* @example
* int is_array = pointerp( ({ 1, 2, 3, 4 }) ); // 1
* int is_array = pointerp( "Foo" ); // 0
Expand Down
5 changes: 2 additions & 3 deletions efuns/fluffos/zh-cn/arrays.zh-cn.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ mixed *shuffle(mixed *arr);

/**
* pointerp() - 确定给定变量是否为数组
* @template {ALL_PRIMITIVE_TYPES} T
* @param {T|T*} arg 要检查的参数
* @returns {arg is T*} 如果'arg'是数组,则返回1,否则返回0。
* @param {mixed} arg 要检查的参数
* @returns {arg is mixed*} 如果'arg'是数组,则返回1,否则返回0。
* @example
* int is_array = pointerp( ({ 1, 2, 3, 4 }) ); // 1
* int is_array = pointerp( "Foo" ); // 0
Expand Down
4 changes: 2 additions & 2 deletions server/src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const finalKeyType = getReducedType(getUnionType(keyTypes, UnionReduction.Subtype));
const finalElementTypes: Type = elementTypes.length > 1 ? createArrayType(getUnionType(elementTypes.map(types => getReducedType(getUnionType(types, UnionReduction.Subtype))))) :
elementTypes.length === 1 ? getReducedType(getUnionType(elementTypes[0], UnionReduction.Subtype)) :
strictNullChecks ? implicitNeverType : undefinedWideningType;
strictNullChecks ? implicitNeverType : autoType;

return createMappingLiteralType(createMappingType(
finalKeyType,
Expand Down Expand Up @@ -2761,7 +2761,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

if (isMappingType(arrayType)) {
return arrayType.resolvedTypeArguments?.length ? getUnionType(arrayType.resolvedTypeArguments) : undefinedWideningType;
return arrayType.resolvedTypeArguments?.length ? getUnionType(arrayType.resolvedTypeArguments) : autoType;
}

return (use & IterationUse.PossiblyOutOfBounds) ? includeUndefinedInIndexSignature(arrayElementType) : arrayElementType;
Expand Down
2 changes: 2 additions & 0 deletions server/src/tests/__snapshots__/compiler.spec.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions server/src/tests/cases/compiler/flowType2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
varargs void set_dir(string dir, string dest, function fn) {}

void test(mapping m) {
foreach (mixed dir, mixed dest in m) {
if (arrayp(dir)) {
foreach (string real_dir in dir) {
if (arrayp(dest)) {
set_dir(real_dir, dest...);
} else {
set_dir(real_dir, dest);
}
}
} else if (arrayp(dest)) {
set_dir(dir, dest...);
} else if (stringp(dest)) {
set_dir(dir, dest);
}
}
}

/**
* this test validates that arrayp assigns the proper array type to a mixed var
* if it does not, the dest... argument will report an error
*/

// @driver: fluffos

0 comments on commit f96c8a3

Please sign in to comment.