diff --git a/compiler/Thrift/Compiler/Typechecker.hs b/compiler/Thrift/Compiler/Typechecker.hs index f8a69a72..25649151 100644 --- a/compiler/Thrift/Compiler/Typechecker.hs +++ b/compiler/Thrift/Compiler/Typechecker.hs @@ -889,15 +889,6 @@ resolveStructuredAnn StructuredAnn{..} = do -- locEndLine defLoc == locStartLine loc | locEndCol defLoc <= locStartCol loc = True | otherwise = False - lookupSchemaRec :: ThriftName -> Loc -> TC l (Some (Schema l)) - lookupSchemaRec name loc = do - thisty <- lookupType name loc - case thisty of - Some ty -> do - let nm = case getAliasedType ty of - TStruct Name{..} _ -> sourceName - _ -> name - lookupSchema nm loc -- Build the Constant Map ------------------------------------------------------ @@ -1121,7 +1112,7 @@ typecheckConst tyTop@(TStruct Name{} _loc) -- First typecheck the struct with the type annotated then check this matches -- the type given at the top level svTypeName <- mkThriftName svType - tschema <- lookupSchema svTypeName lLocation + tschema <- lookupSchemaRec svTypeName lLocation ttyAnn <- lookupType svTypeName lLocation case (tschema, ttyAnn) of (Some schema, Some tyAnn) -> do @@ -1412,6 +1403,16 @@ getAliasedType :: Type l t -> Type l t getAliasedType (TTypedef _ ty _loc) = getAliasedType ty getAliasedType ty = ty +lookupSchemaRec :: ThriftName -> Loc -> TC l (Some (Schema l)) +lookupSchemaRec name loc = do + thisty <- lookupType name loc + case thisty of + Some ty -> do + let nm = case getAliasedType ty of + TStruct Name{..} _ -> sourceName + _ -> name + lookupSchema nm loc + mkFieldMap :: [ListElem MapPair Loc] -> TC l (Map.Map Text (UntypedConst Loc)) diff --git a/tests/if/typedef_struct_const.thrift b/tests/if/typedef_struct_const.thrift new file mode 100644 index 00000000..301ca773 --- /dev/null +++ b/tests/if/typedef_struct_const.thrift @@ -0,0 +1,15 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +typedef Foo Bar + +struct Foo { + 1: i16 a; +} + +const Bar BAR = Bar{a = 1};